diff --git a/src/OneScript.DebugServices/ReconnectableDebugController.cs b/src/OneScript.DebugServices/ReconnectableDebugController.cs index 85809a754..2e4de7de7 100644 --- a/src/OneScript.DebugServices/ReconnectableDebugController.cs +++ b/src/OneScript.DebugServices/ReconnectableDebugController.cs @@ -39,7 +39,6 @@ public class ReconnectableDebugController : IDebugController public ReconnectableDebugController(int port) { _port = port; - _listener = TcpListener.Create(_port); } public IBreakpointManager BreakpointManager => _breakpointManager; @@ -64,6 +63,7 @@ public void Init() private void CreateSession() { + _listener = TcpListener.Create(_port); _channel = new DelayedConnectionChannel(_listener); _server = new DefaultMessageServer(_channel) { @@ -125,6 +125,18 @@ private void DisposeSession() _channel?.Dispose(); _callbackService?.Dispose(); + if (_listener != null) + { + try + { + _listener.Stop(); + } + catch + { + // Listener may already be stopped + } + } + _channel = null; _callbackService = null; _server = null; @@ -132,6 +144,7 @@ private void DisposeSession() _debugger = null; _threadManager = null; _breakpointManager = null; + _listener = null; } private void ThreadManagerOnThreadStopped(object sender, ThreadStoppedEventArgs e) @@ -190,9 +203,6 @@ public void Dispose() DisposeSession(); - _listener?.Stop(); - _listener = null; - _disposed = true; } } diff --git a/src/VSCode.DebugAdapter/DebugeeProcess.cs b/src/VSCode.DebugAdapter/DebugeeProcess.cs index 1d0da524c..c0c2afee6 100644 --- a/src/VSCode.DebugAdapter/DebugeeProcess.cs +++ b/src/VSCode.DebugAdapter/DebugeeProcess.cs @@ -207,6 +207,7 @@ public void HandleDisconnect(bool terminate) return; } _debugger.Disconnect(terminate); + _debugger = null; var mustKill = terminate && !_attachMode;