Fix cases where the socket is closed during a handshake

If the stream is not readable it means that other end has sent the FIN packet.
When this happens we can end the write site of the socket and bail out.

I don't know if this approach has side effects but it seems to work.