Forward port of issue #21629 to 2.4.0-M1.