Backport fix for race condition on shutdown
Merge pull request #104 from trevorbernard/master

Backport fix for race condition on shutdown