fluffle/goirc

Allow user to close connection if server doesn't close after to QUIT.

Closed this issue · 4 comments

It seems the only way to initiate a teardown of the connection is to call conn.Quit() which just sends the QUIT command to the server. If the server ignores this they can force connections to stay open until max file descriptors is hit. It would probably be best to send the QUIT command, wait for tcp close from the server, if it doesn't happen call Close on the net.Conn.

Something like a TIME_WAIT state? Hrm. Could do. Or I could make shutdown public, I guess. I can see there's a reasonable argument to be made that users of the library might expect to be able to force a socket close.

Have you actually run into this problem? If so, where? I note you're writing a twitch bot -- their "IRC" server does some interesting things in the name of scalability. https://blog.twitch.tv/gos-march-to-low-latency-gc-a6fa96f06eb7 is a really interesting read, relatedly.

I made shutdown public, seems like a reasonable thing to do anyway.

@fluffle Since you made the method public, it might be a good idea to consider making it an io.Closer. Not only is it more idiomatic go but you are silencing an error from the net.Conn here:

conn.sock.Close()
Propagating that up the the caller would be useful.

I didn't run into any issues IRL. I could just see a malicious server not respecting QUIT and me getting a call at 3AM.

Thanks for the fix!

That's a great idea, thanks. Now done :-)