backport for #2887