You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jochen Berger <fo...@googlemail.com> on 2011/12/12 09:29:14 UTC
Race condition in T5-pubsub?
Hi list,
I think I've discovered a race condition in the pubsub code which is
kind of funny as I didn't even know these could occur in JavaScript.
The problem seems to be related to the purging of the publisher cache.
The situation I experience the error in is fairly complex (with multiple
listeners subscribing, unsubscribing and signaling, elements being
replaced and the like. I haven't yet been able to reproduce the issue
with a simpler use case and I'm not entirely sure what exactly happens
here. Maybe someone with a better understanding of JavaScript could help
here?
What seems to happen is that one thread (for want of a better word)
calls the createPublisher function. Shortly afterward, another thread
calls the subscribe function on the same topic, leading to the cache for
that topic being cleared.
Now when the first "thread" arrives in line 167, where it says
for (var i = 0; i < publisher.listeners.length; i++) {
publisher.listeners is undefined as the reference was deleted in between.
I managed to fix the issues I encounter by creating a clone of the
publisher.listeners array and using that for the loop.
I would have created a JIRA but I'm quite at a loss as to explaining
what exactly is going on here.
Regards,
Jochen
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Race condition in T5-pubsub?
Posted by Jochen Berger <fo...@googlemail.com>.
Hi,
Am 16.12.2011 17:22, schrieb Howard Lewis Ship:
> Or t5-pub-sub should do a copy-on-write, rather than copying it for
> each iteration.
Hm, I haven't spent much thought on this idea yet, but I don't see how
that could be done in JavaScript.
Also, this still leaves the problem of having to decide whether the
following listeners should be notified for the current run.
Jochen
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Race condition in T5-pubsub?
Posted by Howard Lewis Ship <hl...@gmail.com>.
Or t5-pub-sub should do a copy-on-write, rather than copying it for
each iteration. I miss Clojure collections!
On Thu, Dec 15, 2011 at 3:37 AM, Jochen Berger <fo...@googlemail.com> wrote:
> Hi again,
>
> I think I was wrong with the term "race condition". After some investigation
> I found out what causes the problem. I created a simple demo application
> that I can upload I you want me to.
> Basically, the problem occurs, when there are multiple subscribers for the
> same topic and one of them changes the subscriptions (e.g. by unsubscribing)
> for the topic while the publisher function runs. That will lead to the
> listener cache being cleared and publisher.listeners being undefined upon
> the next iteration of the for loop.
> I think this could be fixed by iterating over a clone of publisher.listeners
> instead of publisher.listeners itself. Of course that would mean that if one
> listener unsubscribes other listeners while running, those would be notified
> for the current run anyway.
> Any thoughts on that?
>
>
> Jochen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
--
Howard M. Lewis Ship
Creator of Apache Tapestry
The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!
(971) 678-5210
http://howardlewisship.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Race condition in T5-pubsub?
Posted by Jochen Berger <fo...@googlemail.com>.
Hi again,
I think I was wrong with the term "race condition". After some
investigation I found out what causes the problem. I created a simple
demo application that I can upload I you want me to.
Basically, the problem occurs, when there are multiple subscribers for
the same topic and one of them changes the subscriptions (e.g. by
unsubscribing) for the topic while the publisher function runs. That
will lead to the listener cache being cleared and publisher.listeners
being undefined upon the next iteration of the for loop.
I think this could be fixed by iterating over a clone of
publisher.listeners instead of publisher.listeners itself. Of course
that would mean that if one listener unsubscribes other listeners while
running, those would be notified for the current run anyway.
Any thoughts on that?
Jochen
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org