manual cherry-pick of dd6cb4a34e, which was originally committed on 5.2. This is the forward port.
dd6cb4a34e