manual cherry-pick of d13928c502a76e8bececbb5befe38475c6c68f8f from master