Handle cases where the socket is closed before being passed to the server

See #32
Merge pull request #34 from lpinca/fix/close-on-handshake

Handle cases where the socket is closed before being passed to the server