backport PR #3885 to 1.8.x

backport of #3885