Partial cherry-pick of d2787a2c44ea019787777fa17cc70d5cef4e48bb