Backported from RCPTT.

RCPTT commit: 229ba2c036591c7654fb24ca6190e0df2ef17e61