OutOfProcessNodeInstance IDispose should WaitForExit #1668

Closed
opened 2025-08-09 17:21:12 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @pauldotknopf on 1/1/2016

When killing the out of process node instance, we should wait for the process to exit (see here).

Otherwise, if you create your own INodeService (Configuration.CreateNodeServices(NodeHostingModel.Http, _scriptsDirectory.TempDirectory)), and then call Dispose() on the service, there is no telling when I can appropriately delete my temporary directory.

Here is my Dispose method in my class that users INodeServices

public void Dispose()
{
    if (_nodeServices != null)
    {
        _nodeServices.Dispose();
        _nodeServices = null;
        // the node services doesn't "WaitForExit". it should though.
        // this should be enough time for the process to fully exit.
        Thread.Sleep(TimeSpan.FromSeconds(2));
    }

    if(_scriptsDirectory != null)
    {
        _scriptsDirectory.Dispose();
        _scriptsDirectory = null;
    }
}
*Originally created by @pauldotknopf on 1/1/2016* When killing the out of process node instance, we should wait for the process to exit (see [here](https://github.com/aspnet/NodeServices/blob/39f7f16/Microsoft.AspNet.NodeServices/HostingModels/OutOfProcessNodeInstance.cs#L141)). Otherwise, if you create your own INodeService (`Configuration.CreateNodeServices(NodeHostingModel.Http, _scriptsDirectory.TempDirectory)`), and then call `Dispose()` on the service, there is no telling when I can appropriately delete my temporary directory. Here is my `Dispose` method in my class that users `INodeServices` ``` c# public void Dispose() { if (_nodeServices != null) { _nodeServices.Dispose(); _nodeServices = null; // the node services doesn't "WaitForExit". it should though. // this should be enough time for the process to fully exit. Thread.Sleep(TimeSpan.FromSeconds(2)); } if(_scriptsDirectory != null) { _scriptsDirectory.Dispose(); _scriptsDirectory = null; } } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#1668
No description provided.