Backport #13512 to 4.0 stable

This backports #13512 to the `4-0-stable` branch.