Forward port of issue #21354 to 2.3.1.