partially cherry-pick c833debccc263076facc2c3fd708bebbb3a7eaa8