Backporting #3935