fix: Fixes timer wheel edge cases (#782)

1. Stopping a different timer, on the same slot as the timer being executed during OnTick
    * Adds a check for the timer wheel currently being executed and does not detach the timer on Stop().
1. Timers are added to the current slot if they need 4095 slots, before the chain is fully detached/executed
    * Removes all chains that will be executed from the timer wheel before executing.
This commit is contained in:
Kamron Batman 2021-09-16 08:52:32 -07:00 committed by GitHub
parent bba5346a92
commit 7785f7e06c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 29 deletions

View file

@ -102,13 +102,18 @@ namespace Server
return;
}
// We are at the head
if (_rings[_ring][_slot] == this)
// Do not detach if we are in the middle of executing the timer wheel for this ring/slot
if (!_timerWheelExecuting || _ringIndexes[_ring] != _slot)
{
_rings[_ring][_slot] = _nextTimer;
// We are at the head
if (_rings[_ring][_slot] == this)
{
_rings[_ring][_slot] = _nextTimer;
}
Detach();
}
Detach();
Running = false;
Version++;
var prof = GetProfile();