backport from 1.9 (rev #9930)

fixed deadlock in case of internal error