Forward port of issue #21466 to 2.2.8.