race conditions fixes

This pull requests fixes race conditions in tests and listener (I've recently created issues in the main repository).
I'm going to merge this PR -- I think the fix to `GracefulListener` is important enough to get in immediately -- but I'm going to revert this change. I agree that there is a race condition in this test but I don't see an easy way around it for now, and I'd rather have the test actually test something than to have the memory model correct =)