[
https://issues.apache.org/activemq/browse/AMQ-930?page=comments#action_36991 ]
james strachan commented on AMQ-930:
------------------------------------
I don't quite understand the reason for this patch - I wonder if you could help
explain it?
Session.DispatchAsyncMessages() is only ever called in a separate thread pool
via a call to ThreadPool.QueueUserWorkItem(new
WaitCallback(session.DispatchAsyncMessages) in the MessageConsumer.
The idea is that only 1 thread at once calls this method for all consumers
created by the session. (In NMS, just like in JMS, messages are only dispatched
from one session at once to however many consumers it has - rather than
dispatching to multiple consumers in parallel).
Am wondering if a better fix is just to ensure that the collection
("consumer.Values") is completely thread safe to avoid the concurrent
modification errors you are seeing. I'm working on a patch right now - will
commit it shortly - am wondering if this is a better approach?
> Session 'consumers' hashtable susceptible to invalid operation exception
> ------------------------------------------------------------------------
>
> Key: AMQ-930
> URL: https://issues.apache.org/activemq/browse/AMQ-930
> Project: ActiveMQ
> Issue Type: Bug
> Components: NMS (C# client)
> Affects Versions: incubation
> Environment: Windows XP, NMS API running against a AMQ 4.0.2 provider
> Reporter: Bryan Schmidt
>
> In a multithreaded environment that reuses the Session object, the following
> exception is thrown:
> Invalid operation exception with the text: "Collection was modified;
> enumeration operation may not execute."
> The exception is thrown when iterating through Session's consumers.Values
> collection. It appears that the lock is being ignored. Spinning up a new
> thread fixes the problem:
> --- Session.cs, DispatchAsyncMessages method ---
> public void DispatchAsyncMessages(object state)
> {
> // lets iterate through each consumer created by this session
> // ensuring that they have all pending messages dispatched
> lock (this)
> {
> // lets ensure that only 1 thread dispatches messages in a
> consumer at once
> foreach (MessageConsumer consumer in consumers.Values)
> {
> ThreadPool.QueueUserWorkItem(new
> WaitCallback(consumer.DispatchAsyncMessages));
> }
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira