Thanks Raphaël Hertzog for the report and help on the patch, and Tim Graham for the review. Backport of 170f7115 from master