mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
A collection that fails once the session has been granted - most plausibly the target exiting before the stop command reaches it - left the task copying the trace connection behind. That connection is torn down on the way out, the copy faults, nobody awaits it, and the finalizer hands it to TaskScheduler.UnobservedTaskException, which this app reports as a crash: a second report of a failure the dialog's error bar had already explained correctly, minutes later and detached from the gesture that caused it. The CollectTracing2 fallback walks the same path, so one dying target produced two of them. The teardown order is the substance of the fix. The session connection has to go first, because after the failure nothing else will ever end the read the copy is parked on; the drain second, so that its own failure is observed rather than abandoned; and the half-copied trace last, so nothing is still writing into it when it is dropped. The regression test pins the invariant rather than the symptom, because the symptom is transport-specific: a Windows named pipe reports an aborted overlapped read as cancellation, and a cancelled task is never unobserved, so only the unix transport can produce the crash at all. What holds everywhere is that no drain may still be running once the failure path is done with it. Assisted-by: Claude:claude-opus-5:Claude Codepull/3943/head
3 changed files with 128 additions and 1 deletions
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
// Copyright (c) 2026 Christoph Wille
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace ICSharpCode.ILSpy.Tests.Processes; |
||||
|
||||
/// <summary>
|
||||
/// Stands in for the connection of an EventPipe session that has been granted but never
|
||||
/// delivers: a read of it completes for one reason only, the stream being torn down, and then
|
||||
/// it fails the way a transport whose far end is gone does. It is the shape of connection a
|
||||
/// collection is left holding when the target dies before the session can be stopped.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only the async read path is implemented, since that is all a copy out of this stream uses;
|
||||
/// the synchronous one would have to block a thread to behave the same way and no caller needs
|
||||
/// it.
|
||||
/// </remarks>
|
||||
sealed class BlockedConnection : Stream |
||||
{ |
||||
readonly TaskCompletionSource tornDown = new(TaskCreationOptions.RunContinuationsAsynchronously); |
||||
|
||||
public override bool CanRead => true; |
||||
public override bool CanSeek => false; |
||||
public override bool CanWrite => false; |
||||
public override long Length => throw new NotSupportedException(); |
||||
public override long Position { |
||||
get => throw new NotSupportedException(); |
||||
set => throw new NotSupportedException(); |
||||
} |
||||
|
||||
public override async ValueTask<int> ReadAsync( |
||||
Memory<byte> buffer, CancellationToken cancellationToken = default) |
||||
{ |
||||
await tornDown.Task.WaitAsync(cancellationToken).ConfigureAwait(false); |
||||
throw new IOException("The connection was torn down under a pending read."); |
||||
} |
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException(); |
||||
public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException(); |
||||
public override void Flush() { } |
||||
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); |
||||
public override void SetLength(long value) => throw new NotSupportedException(); |
||||
|
||||
protected override void Dispose(bool disposing) |
||||
{ |
||||
tornDown.TrySetResult(); |
||||
base.Dispose(disposing); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue