Closes #29133: merged update from 3.6.

Thanks to Evan_ for the report and Marco Buttu for the patch.