Cherry picked from downstream as far as 6c26a4b054b8d50b82cc7fede1e51da16cbbbdad.