Skip to content

Commit

Permalink
Porting random hang fixes (PowerShell#5258)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHigin authored and adityapatwardhan committed Nov 10, 2017
1 parent e0ee555 commit 73188ce
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
27 changes: 19 additions & 8 deletions src/System.Management.Automation/engine/remoting/client/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,14 +1542,25 @@ internal void AssertNotDisposed()
/// </summary>
internal void CloseAllStreams()
{
if (_resultsOwner) _results.Complete();
if (_outputOwner) _output.Complete();
if (_errorOwner) _error.Complete();
if (_progressOwner) _progress.Complete();
if (_verboseOwner) _verbose.Complete();
if (_warningOwner) _warning.Complete();
if (_debugOwner) _debug.Complete();
if (_informationOwner) _information.Complete();
// The Complete() method includes raising public notification events that third parties can
// handle and potentially throw exceptions on the notification thread. We don't want to
// propagate those exceptions because it prevents this thread from completing its processing.
if (_resultsOwner) { try { _results.Complete(); } catch (Exception e) { TraceException(e); } }
if (_outputOwner) { try { _output.Complete(); } catch (Exception e) { TraceException(e); } }
if (_errorOwner) { try { _error.Complete(); } catch (Exception e) { TraceException(e); } }
if (_progressOwner) { try { _progress.Complete(); } catch (Exception e) { TraceException(e); } }
if (_verboseOwner) { try { _verbose.Complete(); } catch (Exception e) { TraceException(e); } }
if (_warningOwner) { try { _warning.Complete(); } catch (Exception e) { TraceException(e); } }
if (_debugOwner) { try { _debug.Complete(); } catch (Exception e) { TraceException(e); } }
if (_informationOwner) { try { _information.Complete(); } catch (Exception e) { TraceException(e); } }
}

private static void TraceException(Exception e)
{
using (PowerShellTraceSource tracer = PowerShellTraceSourceFactory.GetTraceSource())
{
tracer.TraceException(e);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,12 @@ private void WriteInput(object inputValue)
/// <param name="nonblocking">Write in a non-blocking manner</param>
private void WriteJobResults(bool nonblocking)
{
if (_job != null)
if (_job == null)
{
return;
}

try
{
PipelineStoppedException caughtPipelineStoppedException = null;
_job.PropagateThrows = _propagateErrors;
Expand Down Expand Up @@ -1756,7 +1761,12 @@ private void WriteJobResults(bool nonblocking)
session.Name, session.InstanceId));
}
}

}
}
finally
{
if (_job.JobStateInfo.State == JobState.Disconnected)
{
// Allow Invoke-Command to end even though not all remote pipelines
// finished.
HandleThrottleComplete(null, null);
Expand Down

0 comments on commit 73188ce

Please sign in to comment.