Skip to content

InvalidOperationException in DotNetMQ halts all communication #8

@abhithakur88

Description

@abhithakur88

Hi.

Recently in my production environment all the machines stopped sending/receiving messages via DotNetMQ. One machine had following exception in logs:

WARN  2018-04-12 15:18:25,028 [22   ] MDS.Communication.MDSRemoteApplication   - Collection was modified after the enumerator was instantiated.
System.InvalidOperationException: Collection was modified after the enumerator was instantiated.
   at System.Collections.Generic.LinkedList`1.Enumerator.MoveNext()
   at MDS.Communication.MDSRemoteApplication.MessageDeliverer.AsynchronMessageControlTimer_Elapsed(Object state)

This happened 3 to 4 times recently and every time one machine has above Dotnetmq logs. The setup is point-to-point in-memory non-persistent.

I checked the DotnetMQ code. Inside method MessageDeliverer.AsynchronMessageControlTimer_Elapsed(), there is a foreach loop trying to modify the collection which is causing this exception. Following is the extraction:

foreach (var connectedCommunicator in _remoteApplication._communicators)
{
    ...
    //Send communicator to end of the _receiverCommunicators list.
    _remoteApplication._communicators.Remove(connectedCommunicator);
    _remoteApplication._communicators.AddLast(connectedCommunicator);
}

Can you please help to describe what this code is trying to achieve. Can you please also help fixing the above code.

Thanks
Abhishek

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions