From e7bbd6dd3c0c662d0df0023ce258ecaf6efbb64b Mon Sep 17 00:00:00 2001 From: Dietmar Borgards Date: Sun, 25 Oct 2026 09:18:23 +0000 Subject: [PATCH] fix(isotp): dispose the owned actor before unsubscribing in the constructor catch The IsoTpChannel constructor catch detached the BackgroundExceptionOccurred handler before disposing an owned actor. Dispose the actor first and unsubscribe afterwards, the order the J1939/J1939-TP constructors use since #446. Closes #447 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011AJKME1N1ZvnY3yYcPwNoF --- src/CanKit.Pro.IsoTp/IsoTpChannel.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CanKit.Pro.IsoTp/IsoTpChannel.cs b/src/CanKit.Pro.IsoTp/IsoTpChannel.cs index 6c160366..32d5ae4e 100644 --- a/src/CanKit.Pro.IsoTp/IsoTpChannel.cs +++ b/src/CanKit.Pro.IsoTp/IsoTpChannel.cs @@ -262,8 +262,10 @@ internal IsoTpChannel(ICanBusService service, IsoTpEndpoint endpoint, } catch { - _actor.BackgroundExceptionOccurred -= OnActorBackgroundException; + // Unsubscribe only after an owned actor's Dispose, as the J1939 constructors do + // (#442): that is where the actor reports a callback that outlived its shutdown bound. if (_ownsActor) _actor.Dispose(); + _actor.BackgroundExceptionOccurred -= OnActorBackgroundException; throw; }