From b6df02882b5d629d94e9482787e68db6e6343603 Mon Sep 17 00:00:00 2001 From: DYH1319 <1245687900@qq.com> Date: Wed, 4 Nov 2026 14:56:40 +0800 Subject: [PATCH] fix(runtime): stop the socket bridge when it never connected When Electron exits before the socket bridge connects (for example because another instance holds the single-instance lock), RuntimeControllerDotNetFirst stops the bridge, but SocketBridgeService only reaches Stopped through BridgeDisconnected, which a never-connected socket does not raise. The controller then never reaches Stopped and the .NET host hangs forever. Co-Authored-By: Claude Opus 5.5 --- .../Services/SocketBridge/SocketBridgeService.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ElectronNET.API/Runtime/Services/SocketBridge/SocketBridgeService.cs b/src/ElectronNET.API/Runtime/Services/SocketBridge/SocketBridgeService.cs index dd40033..1a80adf 100644 --- a/src/ElectronNET.API/Runtime/Services/SocketBridge/SocketBridgeService.cs +++ b/src/ElectronNET.API/Runtime/Services/SocketBridge/SocketBridgeService.cs @@ -51,6 +51,19 @@ return Task.CompletedTask; } + public override async Task Stop() + { + await base.Stop().ConfigureAwait(false); + + // A socket that never connected never raises BridgeDisconnected, so without this the bridge stays in + // Stopping forever. That happens when Electron exits before the bridge connects (e.g. it lost the + // single-instance lock), and the runtime controller then never reaches Stopped, hanging the .NET host. + if (this.State < LifetimeState.Stopped) + { + this.TransitionState(LifetimeState.Stopped); + } + } + private void Connect() { this.socket.Connect();