Backporting #3929 to 2.3