Make sure the socket is closed properly in the various SSH exit paths.