Forward port of issue #21654 to 2.3.1.