Bugfix: closing client socket should only happen after an exception