From 18d3ffb239bc159d0ddcd78d5d19c77e7c8b4208 Mon Sep 17 00:00:00 2001 From: Deniz Piri Date: Wed, 8 Feb 2023 20:22:48 +0100 Subject: [PATCH] Remove the CancellationTokenSource.Dispose() call inside of the ActorContextExtras.Dispose(). (#1920) It should fix the CancellationTokenDisposed exception issue #1916 --- src/Proto.Actor/Context/ActorContextExtras.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Proto.Actor/Context/ActorContextExtras.cs b/src/Proto.Actor/Context/ActorContextExtras.cs index ca92be6843..1bd86563c5 100644 --- a/src/Proto.Actor/Context/ActorContextExtras.cs +++ b/src/Proto.Actor/Context/ActorContextExtras.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (C) 2015-2022 Asynkron AB All rights reserved // @@ -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;