Forward port of issue #21540 to 2.3.1.