Possible scheduler bug
I was browsing the source in old GitHub repo and have found a potential bug in the scheduler.
I realise there is a very good chance that this code has been rewritten behind the scenes, but I thought I should raise it in case.
It looks like clients can hold pointers to expired and recycled timers.
Example:
- Client A schedules a timer and holds the returned pointer to Timer N
- Timer N expires during tick(). It is cancelled internally and added to the free list.
- Client A now holds a pointer to a cancelled timer. The cancel API is robust against cancelling it again via the active flag. However, client A does not cancel the timer.
- Client B schedules a timer and is returned a pointer to recycled timer N
- Now clients A and B both hold a pointer to the same timer.
- Client A cancels timer N
- Client B's timer never expires and the associated callback is never called.
One possible solution is to return unique IDs instead of pointers, which could incorporate a generation index.
Great project. Hope you plan to release the source again sometime!