GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Porting random hang fixes (#5258) · PowerShell/PowerShell@73188ce

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/System.Management.Automation/engine/remoting
    • client
      • Job.cs
    • commands
      • InvokeCommandCommand.cs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/System.Management.Automation/engine/remoting/client/Job.cs‎

Copy file name to clipboardExpand all lines: src/System.Management.Automation/engine/remoting/client/Job.cs
+19-8Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,14 +1542,25 @@ internal void AssertNotDisposed()
15421542
/// </summary>
15431543
internal void CloseAllStreams()
15441544
{
1545-
if (_resultsOwner) _results.Complete();
1546-
if (_outputOwner) _output.Complete();
1547-
if (_errorOwner) _error.Complete();
1548-
if (_progressOwner) _progress.Complete();
1549-
if (_verboseOwner) _verbose.Complete();
1550-
if (_warningOwner) _warning.Complete();
1551-
if (_debugOwner) _debug.Complete();
1552-
if (_informationOwner) _information.Complete();
1545+
// The Complete() method includes raising public notification events that third parties can
1546+
// handle and potentially throw exceptions on the notification thread. We don't want to
1547+
// propagate those exceptions because it prevents this thread from completing its processing.
1548+
if (_resultsOwner) { try { _results.Complete(); } catch (Exception e) { TraceException(e); } }
1549+
if (_outputOwner) { try { _output.Complete(); } catch (Exception e) { TraceException(e); } }
1550+
if (_errorOwner) { try { _error.Complete(); } catch (Exception e) { TraceException(e); } }
1551+
if (_progressOwner) { try { _progress.Complete(); } catch (Exception e) { TraceException(e); } }
1552+
if (_verboseOwner) { try { _verbose.Complete(); } catch (Exception e) { TraceException(e); } }
1553+
if (_warningOwner) { try { _warning.Complete(); } catch (Exception e) { TraceException(e); } }
1554+
if (_debugOwner) { try { _debug.Complete(); } catch (Exception e) { TraceException(e); } }
1555+
if (_informationOwner) { try { _information.Complete(); } catch (Exception e) { TraceException(e); } }
1556+
}
1557+
1558+
private static void TraceException(Exception e)
1559+
{
1560+
using (PowerShellTraceSource tracer = PowerShellTraceSourceFactory.GetTraceSource())
1561+
{
1562+
tracer.TraceException(e);
1563+
}
15531564
}
15541565

15551566
/// <summary>
Collapse file

‎src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs‎

Copy file name to clipboardExpand all lines: src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,12 @@ private void WriteInput(object inputValue)
16241624
/// <param name="nonblocking">Write in a non-blocking manner</param>
16251625
private void WriteJobResults(bool nonblocking)
16261626
{
1627-
if (_job != null)
1627+
if (_job == null)
1628+
{
1629+
return;
1630+
}
1631+
1632+
try
16281633
{
16291634
PipelineStoppedException caughtPipelineStoppedException = null;
16301635
_job.PropagateThrows = _propagateErrors;
@@ -1756,7 +1761,12 @@ private void WriteJobResults(bool nonblocking)
17561761
session.Name, session.InstanceId));
17571762
}
17581763
}
1759-
1764+
}
1765+
}
1766+
finally
1767+
{
1768+
if (_job.JobStateInfo.State == JobState.Disconnected)
1769+
{
17601770
// Allow Invoke-Command to end even though not all remote pipelines
17611771
// finished.
17621772
HandleThrottleComplete(null, null);

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.