Handling disconnection of sockets