wait until dead *before* cleaning up the temp dir
Merge pull request #5775 from minrk/race-cleanup

wait until dead before cleaning up the temp dir