meebey/SmartIrc4net

Issue with disconnecting

mlapaglia opened this issue · 3 comments

                try
                {
                    while (_Connection.IsConnected &&
                           ((data = _Connection._Reader.ReadLine()) != null))
                    {
                        _Queue.Enqueue(data);
                        QueuedEvent.Set();
                    }
                }

I'm having some problems with this portion of the code. When I am telling the IRC bot to Disconnect(), it is hanging at _Thread.Join() until the ReadLine() goes through the loop (when it receives another message in a channel or anything that causes ReadLine() to have data), at which time it catches the Abort() call.

This is causing me problems with the bot hanging after I tell it to disconnect, it won't actually disconnect until something is first received.

Am I doing something wrong here?

Looks like the socket has to be closed else it blocks inside StreamReader.ReadLine() despite of the thread abort. This issue does NOT happen on Mono, just MS .NET. Their threading implemention seems to be more flaky I guess... Nonetheless SmartIrc4net should use that workaround for the people on the dark side of the forces... Also see:
http://stackoverflow.com/questions/2370534/threadabort-not-working-with-readline-from-a-socket

A work around for this I've found is to always use RfcQuit before disconnecting, this speeds things up significantly.

This happens on Unity so I guess it happens on Mono.
If we disconnect without logging out, the whole app freeze for ThreadAbortException, this is... acceptable.
But if our IRC server is closed accidentally, all the clients app will just all freeze .