Forward port of issue #21906 to 2.3.x.