backport ecf8c209380f from master