Fix potential deadlock
Merge pull request #1 from apportable/master

Fix potential deadlock