@@ -42,6 +42,7 @@ npm install -g node-inspector
42
42
private readonly StringAsTempFile _entryPointScript ;
43
43
private FileSystemWatcher _fileSystemWatcher ;
44
44
private int _invocationTimeoutMilliseconds ;
45
+ private bool _launchWithDebugging ;
45
46
private readonly Process _nodeProcess ;
46
47
private int ? _nodeDebuggingPort ;
47
48
private bool _nodeProcessNeedsRestart ;
@@ -78,9 +79,10 @@ public OutOfProcessNodeInstance(
78
79
OutputLogger = nodeOutputLogger ;
79
80
_entryPointScript = new StringAsTempFile ( entryPointScript ) ;
80
81
_invocationTimeoutMilliseconds = invocationTimeoutMilliseconds ;
82
+ _launchWithDebugging = launchWithDebugging ;
81
83
82
84
var startInfo = PrepareNodeProcessStartInfo ( _entryPointScript . FileName , projectPath , commandLineArguments ,
83
- environmentVars , launchWithDebugging , debuggingPort ) ;
85
+ environmentVars , _launchWithDebugging , debuggingPort ) ;
84
86
_nodeProcess = LaunchNodeProcess ( startInfo ) ;
85
87
_watchFileExtensions = watchFileExtensions ;
86
88
_fileSystemWatcher = BeginFileWatcher ( projectPath ) ;
@@ -103,10 +105,17 @@ public async Task<T> InvokeExportAsync<T>(
103
105
{
104
106
// This special kind of exception triggers a transparent retry - NodeServicesImpl will launch
105
107
// 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).
106
111
var message = _nodeProcess . HasExited
107
112
? "The Node process has exited"
108
113
: "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 ) ;
110
119
}
111
120
112
121
// Construct a new cancellation token that combines the supplied token with the configured invocation
0 commit comments