Same as #2967 but on 4.1 branch