Backport of 22417c2112336b14a21a91819537bd951c15ee60