Backport #3313 to maintenance/1.7.x