Skip to content

Commit

Permalink
Remove the CancellationTokenSource.Dispose() call inside of the Actor…
Browse files Browse the repository at this point in the history
…ContextExtras.Dispose(). (#1920)

It should fix the CancellationTokenDisposed exception issue #1916
  • Loading branch information
DenizPiri committed Feb 8, 2023
1 parent 8023a7a commit 18d3ffb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Proto.Actor/Context/ActorContextExtras.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// <copyright file="ActorContextExtras.cs" company="Asynkron AB">
// Copyright (C) 2015-2022 Asynkron AB All rights reserved
// </copyright>
Expand Down Expand Up @@ -37,7 +37,14 @@ public ActorContextExtras(IContext context)
public void Dispose()
{
ReceiveTimeoutTimer?.Dispose();
CancellationTokenSource.Dispose();
ReceiveTimeoutTimer = null;

// NOTE: We don't dispose CancellationTokenSource here on purpose, doing so causes
// ActorSystem shutdown issues because of DefaultMailbox.PostSystemMessage doing
// a Cancel call on that CancellationTokenSource. This can occur in cases of stopping
// an actor twice. Given that we utilize this CancellationTokenSource only via the Cancel()
// call, doing a Dispose() call is not required. More info can be found here:
// https://github.com/asynkron/protoactor-dotnet/issues/1916
}

public void InitReceiveTimeoutTimer(Timer timer) => ReceiveTimeoutTimer = timer;
Expand Down

0 comments on commit 18d3ffb

Please sign in to comment.