Backports pull request #3564 from master to 1.7.x