Bugfix: Better handling of shutdown of connections.