Fixed deadlock in stubs (cherry picked from commit 68860ca)