@@ -15,6 +15,7 @@ public abstract class OutOfProcessNodeInstance : INodeServices
1515 private readonly object _childProcessLauncherLock ;
1616 private readonly string _commandLineArguments ;
1717 private readonly StringAsTempFile _entryPointScript ;
18+ private Process _nodeProcess ;
1819 private TaskCompletionSource < bool > _nodeProcessIsReadySource ;
1920 private readonly string _projectPath ;
2021 private bool _disposed ;
@@ -27,18 +28,28 @@ public OutOfProcessNodeInstance(string entryPointScript, string projectPath, str
2728 _commandLineArguments = commandLineArguments ?? string . Empty ;
2829 }
2930
30- protected Process NodeProcess { get ; private set ; }
31+ protected Process NodeProcess
32+ {
33+ get
34+ {
35+ // This is only exposed to support the unreliable InputOutputStreamNodeInstance, which is just to verify that
36+ // other hosting/transport mechanisms are possible. This shouldn't really be exposed, and will be removed.
37+ return this . _nodeProcess ;
38+ }
39+ }
3140
3241 public Task < T > Invoke < T > ( string moduleName , params object [ ] args )
3342 => InvokeExport < T > ( moduleName , null , args ) ;
3443
3544 public Task < T > InvokeExport < T > ( string moduleName , string exportedFunctionName , params object [ ] args )
36- => Invoke < T > ( new NodeInvocationInfo
45+ {
46+ return Invoke < T > ( new NodeInvocationInfo
3747 {
3848 ModuleName = moduleName ,
3949 ExportedFunctionName = exportedFunctionName ,
4050 Args = args
4151 } ) ;
52+ }
4253
4354 public void Dispose ( )
4455 {
@@ -52,7 +63,7 @@ protected async Task EnsureReady()
5263 {
5364 lock ( _childProcessLauncherLock )
5465 {
55- if ( NodeProcess == null || NodeProcess . HasExited )
66+ if ( _nodeProcess == null || _nodeProcess . HasExited )
5667 {
5768 var startInfo = new ProcessStartInfo ( "node" )
5869 {
@@ -79,7 +90,7 @@ protected async Task EnsureReady()
7990#endif
8091
8192 OnBeforeLaunchProcess ( ) ;
82- NodeProcess = Process . Start ( startInfo ) ;
93+ _nodeProcess = Process . Start ( startInfo ) ;
8394 ConnectToInputOutputStreams ( ) ;
8495 }
8596 }
@@ -98,7 +109,7 @@ private void ConnectToInputOutputStreams()
98109 var initializationIsCompleted = false ; // TODO: Make this thread-safe? (Interlocked.Exchange etc.)
99110 _nodeProcessIsReadySource = new TaskCompletionSource < bool > ( ) ;
100111
101- NodeProcess . OutputDataReceived += ( sender , evt ) =>
112+ _nodeProcess . OutputDataReceived += ( sender , evt ) =>
102113 {
103114 if ( evt . Data == "[Microsoft.AspNetCore.NodeServices:Listening]" && ! initializationIsCompleted )
104115 {
@@ -111,7 +122,7 @@ private void ConnectToInputOutputStreams()
111122 }
112123 } ;
113124
114- NodeProcess . ErrorDataReceived += ( sender , evt ) =>
125+ _nodeProcess . ErrorDataReceived += ( sender , evt ) =>
115126 {
116127 if ( evt . Data != null )
117128 {
@@ -124,8 +135,8 @@ private void ConnectToInputOutputStreams()
124135 }
125136 } ;
126137
127- NodeProcess . BeginOutputReadLine ( ) ;
128- NodeProcess . BeginErrorReadLine ( ) ;
138+ _nodeProcess . BeginOutputReadLine ( ) ;
139+ _nodeProcess . BeginErrorReadLine ( ) ;
129140 }
130141
131142 protected virtual void OnBeforeLaunchProcess ( )
@@ -151,9 +162,9 @@ protected virtual void Dispose(bool disposing)
151162 _entryPointScript . Dispose ( ) ;
152163 }
153164
154- if ( NodeProcess != null && ! NodeProcess . HasExited )
165+ if ( _nodeProcess != null && ! _nodeProcess . HasExited )
155166 {
156- NodeProcess . Kill ( ) ;
167+ _nodeProcess . Kill ( ) ;
157168 // TODO: Is there a more graceful way to end it? Or does this still let it perform any cleanup?
158169 }
159170
0 commit comments