Forward port of issue #19611 to 2.3.x.