Backporting from 2.12.x to 2.11.x

Re-submission of #3926, with 2.11.x merged and the conflict resolved