Regression in 24959e48d949a20be969f649ece3576dbc7ce422. Backport of d15c61cabbe1c15068ffeb58c64035057f0c7d5c from master.