ws-muse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vinh Nguyen (JIRA)" <>
Subject [jira] Commented: (MUSE-283) SimpleNotificationProducer.getSubscriptions() returns a not-syncronized collection
Date Sat, 05 Jan 2008 22:34:33 GMT


Vinh Nguyen commented on MUSE-283:

Hi Chris,
I I understand your first comment:)  So to fix this bug, the Muse code should
be changed from:

protected synchronized Collection getSubscriptions()  { 
    return Collections.unmodifiableCollection(_subscriptionsByEPR.values());


protected synchronized Collection getSubscriptions()  { 
   return new ArrayList(_subscriptionsByEPR.values()); 

As you pointed out, this ensures that each caller get a new list of the current subscriptions,
instead of everyone getting the same list and possibly encountering the ConcurrentModificationException
if the list is modified during an iteration.

But I realize now that this still doesn't fully address the race condition where a subscription
expires at the same time a notification is published.  So even if a caller has its own list
of subscriptions, then if one of those subscriptions expired, the subscription itself doesn't
prevent a notification from being published afterwards.  This is incorrect behavior.

In SimpleSubscriptionManager, nothing special is done during shutdown(), so a subsequent call
to its publish() method will still succeed.  A fix is also needed in SimpleSubscriptionManager.publish()
to first check if hasBeenShutdown() returns false immediately before calling NotificationProducerClient.notify(NotificationMessage[]).

The same issue seems to appear in SimpleNotificationProducer and possibly many other capabilities.
 No cleanup is done in shutdown(), so calls to any other method after shutdown() can still

A solution to this is to add "sychronized" to both shutdown() and publish().  This may not
be necessary though as long as proper cleanup is done in shutdown(), and publish() and other
methods do proper checks to ensure they don't do anything if shutdown() was already called.

I think to be safe in general, a caller should still check capability.hasBeenShutdown() before
invoking publish() or other methods on the capability.

> SimpleNotificationProducer.getSubscriptions() returns a not-syncronized collection
> ----------------------------------------------------------------------------------
>                 Key: MUSE-283
>                 URL:
>             Project: Muse
>          Issue Type: Bug
>          Components: WSN NotificationProducer
>    Affects Versions: 2.2.0
>         Environment: os: unix on solaris 
>            Reporter: Asaf Zafran
>            Assignee: Dan Jemiolo
>            Priority: Critical
> we have extended the SimpleNotificationProducer.
> in the method 
> public void publish(QName topicName, Element[] content, EndpointReference consumer) throws
> we have called the method:
> Iterator i = getSubsriptions().iterator();
> and the line 
> has caused a ConcurrentModificationException.
> the stack trace is :
> java.util.ConcurrentModificationException
>       	at java.util.HashMap$HashIterator.nextEntry(
>       	at java.util.HashMap$
>       	at java.util.Collections$UnmodifiableCollection$
>       	at
>       	at
>       	at
>       	at
>       	at
>       	at
>       	at
>       	at
>       	at
>       	at
>       	at
>       	at
>       	at

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message