-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #7130: Contention scheduling actions in HashedWheelTimerScheduler #7144
Fix #7130: Contention scheduling actions in HashedWheelTimerScheduler #7144
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self review
if (start) | ||
{ | ||
throw new SchedulerException("cannot enqueue after timer shutdown"); | ||
var timerDuration = TimeSpan.FromTicks(_tickDuration); | ||
_timer ??= new PeriodicTimer(timerDuration); | ||
Task.Run(() => RunAsync(_cts.Token)); // start the clock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not wait on _workerInitialized
if we're the method call that started the timer, because a Wait()
can deadlock the scheduler
private PeriodicTimer? _timer; | ||
private readonly CancellationTokenSource _cts = new(); | ||
|
||
private void Start() | ||
{ | ||
if (_workerState == WORKER_STATE_STARTED) | ||
var start = false; | ||
lock (_lock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - left my data on #7130
Fixes #7130
Changes
Notes
Contention (deadlock) happened when
HashedWheelTimerScheduler.Start()
was called, causing extraneous timer start time or complete deadlock. Note that number is total milliseconds elapsed for eachTimers.StartSingleTimer()
call.