Forward port of issue #21036 to 2.3.0.