Regression in bc7dd8490b882b2cefdc7faf431dc64c532b79c9. Backport of afc708cf6d047b35db57bd7c55baeffef459d279 from master