fix: Fixes timer orphaning issue (#1196)

* Fixes an edge case where a check to see if a timer was being executed resulted in it not being properly detached on stop. Fixed this by changing how we determine what timer is currently being executed.
* Adds execution count to #DEBUG_TIMERS so shards can get notified (rudimentarily for now) about sequentially executing long chains of timers.

Unfortunately, for now, there is no good option when it comes to executing timers. If we execute let's say 500, and defer the rest, that makes all timers effectively 8ms off until it "catches up". Depending on the shard, that may never happen.
This commit is contained in:
Kamron Batman 2022-10-18 18:14:26 -07:00 • committed by GitHub
parent 919b7e9416
commit 791128f238
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 29 deletions

View file

@ -153,20 +153,22 @@ public partial class Timer
Running = false;
// Do not detach if we are in the middle of executing the timer wheel for this ring/slot
if (!_timerWheelExecuting || _ringIndexes[_ring] != _slot)
// We are the head on the timer ring
if (_rings[_ring][_slot] == this)
{
// We are at the head
if (_rings[_ring][_slot] == this)
{
_rings[_ring][_slot] = _nextTimer;
}
Detach();
OnDetach();
_rings[_ring][_slot] = _nextTimer;
}
// We are the head on the executing ring
if (_executingRings[_ring] == this)
{
_executingRings[_ring] = _nextTimer;
}
Detach();
Version++;
OnDetach();
var prof = GetProfile();
if (prof != null)