Forward port of issue #21595 to 2.3.1.