Fix race condition that causes diamond to hang at shutdown.