fix #21066, fix #18693, manually merge pull request #165