backport from pull request #3863