Backport of #3687 to 1.4.x