Porting PR #2843 to 2.5.x