Fix hang during shutdown when client is connected.

Closes #108.