backport PR #3885 to 1.7.x

backport of #3885