you're synchronized on shutdownGracefully.  Is it possible we are active at this check, but then become inactive ungracefully?  I'm assuming that is also synchronized?  I see that the handshake case is covered below in the else{}