From 26e8bd823cd26401372264ea5dfeb3f6ac55ed70 Mon Sep 17 00:00:00 2001 From: SteveSandersonMS Date: Thu, 7 Jul 2016 12:01:28 +0100 Subject: [PATCH] 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. --- .../Content/Node/entrypoint-http.js | 5 ++++- .../Content/Node/entrypoint-socket.js | 5 ++++- .../HostingModels/OutOfProcessNodeInstance.cs | 8 ++++++++ .../TypeScript/Util/AutoQuit.ts | 6 +++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-http.js b/src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-http.js index edf5949..9e665ab 100644 --- a/src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-http.js +++ b/src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-http.js @@ -184,7 +184,10 @@ var ext = path.extname(filename); if (extensions.indexOf(ext) >= 0) { console.log('Restarting due to file change: ' + filename); - process.exit(0); + // Temporarily, the file-watching logic is in Node, so we signal it's time to restart by + // sending the following message back to .NET. Soon the file-watching logic will move over + // to the .NET side, and this whole file can be removed. + console.log('[Microsoft.AspNetCore.NodeServices:Restart]'); } }); } diff --git a/src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-socket.js b/src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-socket.js index 355bbbb..3035b34 100644 --- a/src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-socket.js +++ b/src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-socket.js @@ -95,7 +95,10 @@ var ext = path.extname(filename); if (extensions.indexOf(ext) >= 0) { console.log('Restarting due to file change: ' + filename); - process.exit(0); + // Temporarily, the file-watching logic is in Node, so we signal it's time to restart by + // sending the following message back to .NET. Soon the file-watching logic will move over + // to the .NET side, and this whole file can be removed. + console.log('[Microsoft.AspNetCore.NodeServices:Restart]'); } }); } diff --git a/src/Microsoft.AspNetCore.NodeServices/HostingModels/OutOfProcessNodeInstance.cs b/src/Microsoft.AspNetCore.NodeServices/HostingModels/OutOfProcessNodeInstance.cs index 498c316..b81651d 100644 --- a/src/Microsoft.AspNetCore.NodeServices/HostingModels/OutOfProcessNodeInstance.cs +++ b/src/Microsoft.AspNetCore.NodeServices/HostingModels/OutOfProcessNodeInstance.cs @@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels public abstract class OutOfProcessNodeInstance : INodeInstance { private const string ConnectionEstablishedMessage = "[Microsoft.AspNetCore.NodeServices:Listening]"; + private const string NeedsRestartMessage = "[Microsoft.AspNetCore.NodeServices:Restart]"; private readonly TaskCompletionSource _connectionIsReadySource = new TaskCompletionSource(); private bool _disposed; private readonly StringAsTempFile _entryPointScript; @@ -128,6 +129,13 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels _connectionIsReadySource.SetResult(null); initializationIsCompleted = true; } + else if (evt.Data == NeedsRestartMessage) + { + // Temporarily, the file-watching logic is in Node, so look out for the + // signal that we need to restart. This can be removed once the file-watching + // logic is moved over to the .NET side. + Dispose(); + } else if (evt.Data != null) { OnOutputDataReceived(evt.Data); diff --git a/src/Microsoft.AspNetCore.NodeServices/TypeScript/Util/AutoQuit.ts b/src/Microsoft.AspNetCore.NodeServices/TypeScript/Util/AutoQuit.ts index e65567c..5c75c1c 100644 --- a/src/Microsoft.AspNetCore.NodeServices/TypeScript/Util/AutoQuit.ts +++ b/src/Microsoft.AspNetCore.NodeServices/TypeScript/Util/AutoQuit.ts @@ -8,7 +8,11 @@ export function autoQuitOnFileChange(rootDir: string, extensions: string[]) { var ext = path.extname(filename); if (extensions.indexOf(ext) >= 0) { console.log('Restarting due to file change: ' + filename); - process.exit(0); + + // Temporarily, the file-watching logic is in Node, so we signal it's time to restart by + // sending the following message back to .NET. Soon the file-watching logic will move over + // to the .NET side, and this whole file can be removed. + console.log('[Microsoft.AspNetCore.NodeServices:Restart]'); } }); }