Thanks to Reto Aebersold for reporting the issue and Tim Graham and Claude Paroz for the review. Backport of faad6070ee from master
faad6070ee