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 <noreply@anthropic.com>
This commit is contained in:
DYH1319
2026-11-04 14:56:40 +08:00
parent 05aa92e415
commit b6df02882b

View File

@@ -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();