Sorcerer's Apprentice Bug and Solution
Ever heard of Sorcerer’s Apprentice? It is a poem by Goethe, set to music by Paul Dukas, and visualized by Walt Disney in the Movie ‘Fantasia’. (See: http://www.youtube.com/watch?v=XChxLGnIwCU)
In the movie, Mickey Mouse, the apprentice, dons the Sorcerer’s cap to animate a broom so that it will do Mickey’s chores for him. The broom soon gets out of control, and Mickey is forced to hack up the broom with an axe. But then each of the splinters of the broom become a broom, and Mickey’s troubles intensify.
For each click, the number of event handlers grows as follows:
Click # of Event Handlers
So after the second click, there are two event handlers.
On the 3rd click, the two event handlers each delegate a new event handler(now there are 4), each toggle the subscription state, (essentially canceling each other out) and the state appears unchanged. Since the number of event handlers is always even, their collective execution will always return the subscription state to the same state as that before they were executed.
Example: 3rd click, 4 event handlers, state: subscribed, Event handlers result in the following state chain: unsubscribed->subscribed->unsubscribed->subscribed, and were are right back where we started from.
This is a dangerous bug, because when nothing happens, users tend to click again and again, and 10 clicks (for example) = 2^9=512 event handlers.
A fix that works, but might not be the correct one, because it breaks the encapsulation of wpList (we must peer inside wpList to know that the event handler is bound to the subscription link via .delegate()) is to do the following:
In topic.js, function ubsLinkSetup(), replace the line
subscriptionToggle.get(0).wpList.process( subscriptionToggle );
subscriptionToggle.get(0).wpList.process( subscriptionToggle.undelegate() );
This removes the event handler before adding it back.
Parallel fix for favorites.
Hoping to see some fix in the next release
- You must be logged in to reply to this topic.