Forward port of issue #50916 to 4.1.x.
Forward port of issue #50916 to 4.1.x.