Porting master PR #2826 to 2.5x