IrcDotNet
IrcDotNet copied to clipboard
Unhanded exception
After running a system using an IRC connection for a while, the system throws the following exception:
Unhandled Exception: System.InvalidOperationException: Sequence contains more than one matching element at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable
1 source, Func2 predicate) at IrcDotNet.IrcChannel.GetChannelUser(IrcUser user) in C:\Users\Martin\Desktop\IrcDotNet\source\IrcDotNet\IrcChannel.cs:line 191 at IrcDotNet.TwitchIrcClient.OnChannelModeChanged(IrcChannel channel, IrcUser source, String newModes, IEnumerable`1 newModeParameters) in C:\Users\Martin\Desktop\IrcDotNet\source\IrcDotNet\TwitchIrcClient.cs:line 24 at IrcDotNet.IrcClient.ProcessMessageMode(IrcMessage message) in C:\Users\Martin\Desktop\IrcDotNet\source\IrcDotNet\IrcClientMessageProcessing.cs:line 114 at IrcDotNet.IrcClient.ReadMessage(IrcMessage message, String line) in C:\Users\Martin\Desktop\IrcDotNet\source\IrcDotNet\IrcClient.cs:line 1470 at IrcDotNet.IrcClient.ParseMessage(String line) in C:\Users\Martin\Desktop\IrcDotNet\source\IrcDotNet\IrcClient.cs:line 1648 at IrcDotNet.StandardIrcClient.ReceiveCompleted(Object sender, SocketAsyncEventArgs e) in C:\Users\Martin\Desktop\IrcDotNet\source\IrcDotNet\StandardIrcClient.cs:line 375 at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e) at System.Net.Sockets.SocketAsyncEventArgs.ExecutionCallback(Object ignored) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Objectstate, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags) at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
I suspect this is a race condition as the operations for modifying collections when for example adding a ChannelUser in IrcChannel is not atomic.
Couple things here.
We should both ensure the collection can only ever have one matching element added (probably as you say a race condition) and we should also probably switch to FirstOrDefault to avoid the crash.
This is still happily crashing the lib in a rather "regular" manner (somtimes hours, sometimes days).