Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Polyfill/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
// signal is not disposed: a handler already running can still Release it after unsubscribe
}
}

Expand Down Expand Up @@ -313,7 +313,7 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
// signal is not disposed: a handler already running can still Release it after unsubscribe
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/net10.0/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -222,7 +221,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/net461/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -268,7 +267,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/net462/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -268,7 +267,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/net47/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -268,7 +267,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/net471/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -268,7 +267,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/net472/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -268,7 +267,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/net48/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -268,7 +267,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/net481/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -268,7 +267,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/net5.0/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -222,7 +221,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/net6.0/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -222,7 +221,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/net7.0/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -222,7 +221,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/net8.0/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -222,7 +221,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/net9.0/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -222,7 +221,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/netcoreapp2.0/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -268,7 +267,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/netcoreapp2.1/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -268,7 +267,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/netcoreapp2.2/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -268,7 +267,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/netcoreapp3.0/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -259,7 +258,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/netcoreapp3.1/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -259,7 +258,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/netstandard2.0/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -268,7 +267,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/netstandard2.1/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -268,7 +267,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/Split/uap10.0/Polyfill_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public static IEnumerable<ProcessOutputLine> ReadAllLines(this Process target, T
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
static int RemainingMilliseconds(Stopwatch watch, TimeSpan? timeout)
Expand Down Expand Up @@ -268,7 +267,6 @@ public static async IAsyncEnumerable<ProcessOutputLine> ReadAllLinesAsync(
{
target.OutputDataReceived -= outHandler;
target.ErrorDataReceived -= errHandler;
signal.Dispose();
}
}
#endif
Expand Down
29 changes: 29 additions & 0 deletions src/Tests/PolyfillTests_Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,35 @@ public async Task Process_ReadAllLines_Timeout()
await Assert.That(first.Content.Length).IsGreaterThan(0);
}

// Races the reader disposing its signal against the final handler Release.
// Losing the race crashes the test host with an unhandled exception on a thread pool thread.
[Test]
public async Task Process_ReadAllLines_Stress()
{
for (var i = 0; i < 100; i++)
{
using var process = StartRedirected("--version");
var lines = process.ReadAllLines().ToList();
await Assert.That(lines.Count).IsGreaterThan(0);
}
}

[Test]
public async Task Process_ReadAllLinesAsync_Stress()
{
for (var i = 0; i < 100; i++)
{
using var process = StartRedirected("--version");
var count = 0;
await foreach (var _ in process.ReadAllLinesAsync())
{
count++;
}

await Assert.That(count).IsGreaterThan(0);
}
}

static Process StartRedirected(string arguments)
{
var process = new Process
Expand Down
Loading