Thanks Eneko Illarramendi for the report and initial patch. Backport of 8c538871bd from master.
8c538871bd
Backport of 4d60261b2a from master
4d60261b2a
Backport of fd4698fe3f from master
fd4698fe3f