Thanks Patrick Strasser for the suggestion and Zbigniew Siciarz for the patch. Backport of 722683f508 from master.