Backport #378 in 2.3 branch