@@ -42,6 +42,7 @@ npm install -g node-inspector
4242 private readonly StringAsTempFile _entryPointScript ;
4343 private FileSystemWatcher _fileSystemWatcher ;
4444 private int _invocationTimeoutMilliseconds ;
45+ private bool _launchWithDebugging ;
4546 private readonly Process _nodeProcess ;
4647 private int ? _nodeDebuggingPort ;
4748 private bool _nodeProcessNeedsRestart ;
@@ -78,9 +79,10 @@ public OutOfProcessNodeInstance(
7879 OutputLogger = nodeOutputLogger ;
7980 _entryPointScript = new StringAsTempFile ( entryPointScript ) ;
8081 _invocationTimeoutMilliseconds = invocationTimeoutMilliseconds ;
82+ _launchWithDebugging = launchWithDebugging ;
8183
8284 var startInfo = PrepareNodeProcessStartInfo ( _entryPointScript . FileName , projectPath , commandLineArguments ,
83- environmentVars , launchWithDebugging , debuggingPort ) ;
85+ environmentVars , _launchWithDebugging , debuggingPort ) ;
8486 _nodeProcess = LaunchNodeProcess ( startInfo ) ;
8587 _watchFileExtensions = watchFileExtensions ;
8688 _fileSystemWatcher = BeginFileWatcher ( projectPath ) ;
@@ -103,10 +105,17 @@ public async Task<T> InvokeExportAsync<T>(
103105 {
104106 // This special kind of exception triggers a transparent retry - NodeServicesImpl will launch
105107 // a new Node instance and pass the invocation to that one instead.
108+ // Note that if the Node process is listening for debugger connections, then we need it to shut
109+ // down immediately and not stay open for connection draining (because if it did, the new Node
110+ // instance wouldn't able to start, because the old one would still hold the debugging port).
106111 var message = _nodeProcess . HasExited
107112 ? "The Node process has exited"
108113 : "The Node process needs to restart" ;
109- throw new NodeInvocationException ( message , null , nodeInstanceUnavailable : true ) ;
114+ throw new NodeInvocationException (
115+ message ,
116+ details : null ,
117+ nodeInstanceUnavailable : true ,
118+ allowConnectionDraining : ! _launchWithDebugging ) ;
110119 }
111120
112121 // Construct a new cancellation token that combines the supplied token with the configured invocation
0 commit comments