backport of fix #29