mrniko / netty-socketio

Socket.IO server implemented on Java. Realtime java framework
Apache License 2.0
6.82k stars 1.65k forks source link

CancelableScheduler potential race condition where cancels are not respected #104

Closed msmyers closed 9 years ago

msmyers commented 10 years ago

If you call schedule, it is possible to miss a cancellation if you call cancel before it is added to the map.

executorService.schedule() is called.

Before we put it in the map via scheduledFutures.put(..) we call cancel. It is not found in the cancellation map so therefore not cancelled.

Since we're cancelling all timers on disconnect (a separate bug fix), this becomes an issue if a user disconnects while a timer is being scheduled. Slim possible chance, but non-zero.

We fixed by using coarse grained synchronization across the whole class. The reason we thought this was ok (rather than finely grained synchronization) is because the map.put/remove is a constant time (or log(n) time) operation.

https://github.com/Zipwhip/netty-socketio/commit/12aa05292370fcf6377679b880fbffda6748fc3d

mrniko commented 9 years ago

timeout.isExpired check added