Uploaded image for project: 'ActiveMQ .Net'
  1. ActiveMQ .Net
  2. AMQNET-342

"Collection was modified" exception when adding message consumer

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.5.1
    • 1.5.2, 1.6.0
    • NMS
    • None
    • Windows XP

    Description

      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 Listener"

      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.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            jgomes Jim Gomes
            aparkin Andrew Parkin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment