Partial cherry-pick of d5ff5b4433cfa00b8673980acceeb36fe6ee2a51