Skip to content

Commit 26e8bd8

Browse files
Instead of the Node process exiting instantly on file change, send a signal to .NET that it should restart. This is working towards the connection-draining feature.
1 parent a19e37f commit 26e8bd8

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

‎src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-http.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@
184184
varext=path.extname(filename);
185185
if(extensions.indexOf(ext)>=0){
186186
console.log('Restarting due to file change: '+filename);
187-
process.exit(0);
187+
// Temporarily, the file-watching logic is in Node, so we signal it's time to restart by
188+
// sending the following message back to .NET. Soon the file-watching logic will move over
189+
// to the .NET side, and this whole file can be removed.
190+
console.log('[Microsoft.AspNetCore.NodeServices:Restart]');
188191
}
189192
});
190193
}

‎src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-socket.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@
9595
varext=path.extname(filename);
9696
if(extensions.indexOf(ext)>=0){
9797
console.log('Restarting due to file change: '+filename);
98-
process.exit(0);
98+
// Temporarily, the file-watching logic is in Node, so we signal it's time to restart by
99+
// sending the following message back to .NET. Soon the file-watching logic will move over
100+
// to the .NET side, and this whole file can be removed.
101+
console.log('[Microsoft.AspNetCore.NodeServices:Restart]');
99102
}
100103
});
101104
}

‎src/Microsoft.AspNetCore.NodeServices/HostingModels/OutOfProcessNodeInstance.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
1818
publicabstractclassOutOfProcessNodeInstance:INodeInstance
1919
{
2020
privateconststringConnectionEstablishedMessage="[Microsoft.AspNetCore.NodeServices:Listening]";
21+
privateconststringNeedsRestartMessage="[Microsoft.AspNetCore.NodeServices:Restart]";
2122
privatereadonlyTaskCompletionSource<object>_connectionIsReadySource=newTaskCompletionSource<object>();
2223
privatebool_disposed;
2324
privatereadonlyStringAsTempFile_entryPointScript;
@@ -128,6 +129,13 @@ private void ConnectToInputOutputStreams()
128129
_connectionIsReadySource.SetResult(null);
129130
initializationIsCompleted=true;
130131
}
132+
elseif(evt.Data==NeedsRestartMessage)
133+
{
134+
// Temporarily, the file-watching logic is in Node, so look out for the
135+
// signal that we need to restart. This can be removed once the file-watching
136+
// logic is moved over to the .NET side.
137+
Dispose();
138+
}
131139
elseif(evt.Data!=null)
132140
{
133141
OnOutputDataReceived(evt.Data);

‎src/Microsoft.AspNetCore.NodeServices/TypeScript/Util/AutoQuit.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ export function autoQuitOnFileChange(rootDir: string, extensions: string[]){
88
varext=path.extname(filename);
99
if(extensions.indexOf(ext)>=0){
1010
console.log('Restarting due to file change: '+filename);
11-
process.exit(0);
11+
12+
// Temporarily, the file-watching logic is in Node, so we signal it's time to restart by
13+
// sending the following message back to .NET. Soon the file-watching logic will move over
14+
// to the .NET side, and this whole file can be removed.
15+
console.log('[Microsoft.AspNetCore.NodeServices:Restart]');
1216
}
1317
});
1418
}

0 commit comments

Comments
(0)