fix bug where attempting to close a handle when the ssh session had already died started a loop