backport of #3433