backport #1938 for 2.2.x