activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Parkin (JIRA)" <>
Subject [jira] [Updated] (AMQNET-342) "Collection was modified" exception when adding message consumer
Date Wed, 14 Sep 2011 09:16:09 GMT


Andrew Parkin updated AMQNET-342:

    Attachment: consumercreator.cs

I can now reproduce the problem every time with the attached code sample.  This starts a number
of threads which all create consumers on a destination.  Usually the error will occur around
the 90th thread, I've attached some of the program's output which shows the exception occurring.
 I don't think writing this as an NUnit test would be useful as it's difficult to guarantee
the problem will occur every time, on different hardware it might only occur on the 500th
thread.  The only other way to reproduce it e.g. with 2 threads would be to artificially slow
down the ActiveMQ code but I'm still having problems building it at present.

I hope this is useful, please let me know if you need any more info.  Thanks.

> "Collection was modified" exception when adding message consumer
> ----------------------------------------------------------------
>                 Key: AMQNET-342
>                 URL:
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: NMS
>    Affects Versions: 1.5.1
>         Environment: Windows XP
>            Reporter: Andrew Parkin
>            Assignee: Jim Gomes
>         Attachments: consumercreator.cs
> I am occasionally seeing the exception below when executing the following code:
> IMessageConsumer consumer = session.CreateConsumer(dest);
> consumer.Listener += BufferMessage;
> System.InvalidOperationException: Collection was modified; enumeration operation may
not execute.
>    at System.Collections.Hashtable.HashtableEnumerator.MoveNext()
>    at Apache.NMS.ActiveMQ.Session.Start()
>    at Apache.NMS.ActiveMQ.MessageConsumer.add_Listener(MessageListener value)
> Putting locks around the code in my application doesn't prevent the problem.  I've had
a look at the ActiveMQ source & I suspect the problem is as follows:
> MessageConsumer invokes the following code in the "add" section of "public event MessageListener
> if(wasStarted == true)
> {
>    this.session.Start();
> }
> ...and Session.Start() iterates over consumers.values as follows:
> foreach(MessageConsumer consumer in this.consumers.Values)
> {
>    consumer.Start();
> }
> I noticed that everywhere else in Session where this iteration occurs is locked with
"lock(this.consumers.SyncRoot)", except for in the Start() method.  Does a lock also need
to be put around this section as well?
> Unfortunately I'm having problems building the source at the moment so I'm unable to
confirm whether this would fix the problem or not.

This message is automatically generated by JIRA.
For more information on JIRA, see:


View raw message