Fix race condition that causes diamond to hang at shutdown.
Merge pull request #350 from lambdafu/master

Fix race condition where diamond hangs at shutdown.