Forward port of issue #21596 to 2.3.1.