Skip to content

Commit

Permalink
Merge pull request #2315 from Aaronontheweb/fix-2314-hwt
Browse files Browse the repository at this point in the history
close #2314 - fixes shutdown race condition with HashedWheelTimer
  • Loading branch information
alexvaluyskiy authored Sep 21, 2016
2 parents 8086e25 + 8c87818 commit 078b7d6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/core/Akka/Actor/Scheduler/HashedWheelTimerScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,11 @@ protected override void InternalScheduleRepeatedly(TimeSpan initialDelay, TimeSp
private Task<IEnumerable<SchedulerRegistration>> Stop()
{
var p = new TaskCompletionSource<IEnumerable<SchedulerRegistration>>();

if (_stopped.CompareAndSet(null, p)
#pragma warning disable 420
if (Interlocked.CompareExchange(ref _workerState, WORKER_STATE_SHUTDOWN, WORKER_STATE_STARTED) == WORKER_STATE_STARTED
&& Interlocked.CompareExchange(ref _workerState, WORKER_STATE_SHUTDOWN, WORKER_STATE_STARTED) == WORKER_STATE_STARTED)
#pragma warning restore 420
&& _stopped.CompareAndSet(null, p))
{
// Let remaining work that is already being processed finished. The termination task will complete afterwards
return p.Task;
Expand Down

0 comments on commit 078b7d6

Please sign in to comment.