9.x backport fix for issue4211

backport issue4211 from master