Backport #7259

Backport #7259

@karlitschek Please review