Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
AsyncFoldLeft not threadsafe if collection is concurrently modified can result in closed Websockets #899
Even though the listeners in ServerChannelImpl._listeners are a concurrently-modification safe CopyOnWriteArrayList the looping in BayeuxServerImpl#notifyListeners using AsyncFoldLeft is not.
AsyncFoldLeft#run takes the size of the collection at the beginning and calls List#get with an increasing index.
A if listeners got added, they will not be notified in this run
C is a disaster
i think the simplest correct fix would be to clone the listeners list before entering the AsyncFoldLeft to ensure it is a stable collection iterated over.
more elegantly the indexedbased iteration could be replaced with using the iterator of the copyonwritearraylist which is also guarantueed to be stable even under concurrent modification.
cometd version: Bayeux 5.0.0-BETA1
I digged further through the code and the fix could be very minimal by removing the
If that overload would be removed all current callsites would invoke