Forward port of issue #21319 to 2.3.0.