提交 7e4f3149 编写于 作者: A Artur Spychaj 提交者: GitHub

Merge pull request #11904 from drognanar/fixreploutput2

Print remaining REPL output if it crashes in VS host
......@@ -20,7 +20,8 @@ internal sealed class RemoteService
// output pumping threads (stream output from stdout/stderr of the host process to the output/errorOutput writers)
private Thread _readOutputThread; // nulled on dispose
private Thread _readErrorOutputThread; // nulled on dispose
private InteractiveHost _host; // nulled on dispose
private InteractiveHost _host; // nulled on dispose
private bool _disposing; // set to true on dispose
internal RemoteService(InteractiveHost host, Process process, int processId, Service service)
{
......@@ -29,6 +30,7 @@ internal RemoteService(InteractiveHost host, Process process, int processId, Ser
Debug.Assert(service != null);
_host = host;
_disposing = false;
this.Process = process;
_processId = processId;
this.Service = service;
......@@ -61,7 +63,7 @@ internal void HookAutoRestartEvent()
{
Process.Exited -= localHandler;
if (!IsDisposed)
if (!_disposing)
{
await _host.OnProcessExited(Process).ConfigureAwait(false);
}
......@@ -73,7 +75,7 @@ internal void HookAutoRestartEvent()
}
};
// hook the even only once per process:
// hook the event only once per process:
if (Interlocked.Exchange(ref processExitHandling, ProcessExitHooked) == 0)
{
Process.Exited += localHandler;
......@@ -110,12 +112,10 @@ private void ReadOutput(bool error)
}
}
private bool IsDisposed => _host == null;
internal void Dispose(bool joinThreads)
{
// null the host so that we don't attempt to restart or write to the buffer anymore:
_host = null;
// set _disposing so that we don't attempt restart the host anymore:
_disposing = true;
InitiateTermination(Process, _processId);
......@@ -147,6 +147,9 @@ internal void Dispose(bool joinThreads)
}
}
// null the host so that we don't attempt to write to the buffer anymore:
_host = null;
_readOutputThread = _readErrorOutputThread = null;
}
......
......@@ -76,7 +76,7 @@ internal Process TryGetProcess()
internal Service TryGetService()
{
var initializedService = TryGetOrCreateRemoteServiceAsync().Result;
var initializedService = TryGetOrCreateRemoteServiceAsync(processPendingOutput: false).Result;
return initializedService.ServiceOpt?.Service;
}
......@@ -312,7 +312,7 @@ private LazyRemoteService CreateRemoteService(InteractiveHostOptions options, bo
private Task OnProcessExited(Process process)
{
ReportProcessExited(process);
return TryGetOrCreateRemoteServiceAsync();
return TryGetOrCreateRemoteServiceAsync(processPendingOutput: true);
}
private void ReportProcessExited(Process process)
......@@ -333,7 +333,7 @@ private void ReportProcessExited(Process process)
}
}
private async Task<InitializedRemoteService> TryGetOrCreateRemoteServiceAsync()
private async Task<InitializedRemoteService> TryGetOrCreateRemoteServiceAsync(bool processPendingOutput)
{
try
{
......@@ -357,7 +357,7 @@ private async Task<InitializedRemoteService> TryGetOrCreateRemoteServiceAsync()
if (previousService == currentRemoteService)
{
// we replaced the service whose process we know is dead:
currentRemoteService.Dispose(joinThreads: false);
currentRemoteService.Dispose(processPendingOutput);
currentRemoteService = newService;
}
else
......@@ -387,7 +387,7 @@ private async Task<TResult> Async<TResult>(Action<Service, RemoteAsyncOperation<
{
try
{
var initializedService = await TryGetOrCreateRemoteServiceAsync().ConfigureAwait(false);
var initializedService = await TryGetOrCreateRemoteServiceAsync(processPendingOutput: false).ConfigureAwait(false);
if (initializedService.ServiceOpt == null)
{
return default(TResult);
......@@ -434,7 +434,7 @@ public async Task<RemoteExecutionResult> ResetAsync(InteractiveHostOptions optio
oldService.Dispose(joinThreads: false);
}
var initializedService = await TryGetOrCreateRemoteServiceAsync().ConfigureAwait(false);
var initializedService = await TryGetOrCreateRemoteServiceAsync(processPendingOutput: false).ConfigureAwait(false);
if (initializedService.ServiceOpt == null)
{
return default(RemoteExecutionResult);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册