Backport efe33c508e140c595a2020ceff4f5a3f4006d9c1

Fixes #1788 in stable45

please review  @LukasReschke @Raydiation @tanghus