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
Original file line number Diff line number Diff line change
Expand Up @@ -215,26 +215,4 @@ public static void ValidateNotNull(string argumentName, string resourceName, obj
throw new ArgumentNullException(argumentName, SR.Format(resourceName, propertyName));
}
}

public static void ObserveException(this Task task)
{
if (task.IsCompleted)
{
ObserveExceptionCore(task);
}
else
{
task.ContinueWith(static (t) => ObserveExceptionCore(t), CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Default);
}

static void ObserveExceptionCore(Task task)
{
Debug.Assert(task.IsCompleted);
if (task.IsFaulted)
{
// Access Exception to avoid TaskScheduler.UnobservedTaskException firing.
Exception? e = task.Exception!.InnerException;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -658,14 +658,22 @@ private unsafe int HandleEventShutdownInitiatedByTransport(ref SHUTDOWN_INITIATE
{
Exception exception = ExceptionDispatchInfo.SetCurrentStackTrace(ThrowHelper.GetExceptionForMsQuicStatus(data.Status, (long)data.ErrorCode));
_connectedTcs.TrySetException(exception);
_connectionCloseTcs.TrySetException(exception);
if (_connectionCloseTcs.TrySetException(exception))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we extract it as a method? as it's used 3 times

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it from ThrowHelper as it's only 2 liner and only used for _connectionCloseTcs. But I can shuffle it back, I don't care that much about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking it can sit within QuicConnection then?
Plus, extracting it will save us explaining why it's like that in a comment each time

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to pollute QuicConnection with a helper method, that's the worst option for me 😢

{
// Observe the exception as the task is used only for internal workings and might not be observed.
_ = _connectionCloseTcs.Task.Exception;
}
_acceptQueue.Writer.TryComplete(exception);
return QUIC_STATUS_SUCCESS;
}
private unsafe int HandleEventShutdownInitiatedByPeer(ref SHUTDOWN_INITIATED_BY_PEER_DATA data)
{
Exception exception = ExceptionDispatchInfo.SetCurrentStackTrace(ThrowHelper.GetConnectionAbortedException((long)data.ErrorCode));
_connectionCloseTcs.TrySetException(exception);
if (_connectionCloseTcs.TrySetException(exception))
{
// Observe the exception as the task is used only for internal workings and might not be observed.
_ = _connectionCloseTcs.Task.Exception;
}
_acceptQueue.Writer.TryComplete(exception);
return QUIC_STATUS_SUCCESS;
}
Expand All @@ -675,7 +683,11 @@ private unsafe int HandleEventShutdownComplete()
_tlsSecret?.WriteSecret();

Exception exception = ExceptionDispatchInfo.SetCurrentStackTrace(_disposed ? new ObjectDisposedException(GetType().FullName) : ThrowHelper.GetOperationAbortedException());
_connectionCloseTcs.TrySetException(exception);
if (_connectionCloseTcs.TrySetException(exception))
{
// Observe the exception as the task is used only for internal workings and might not be observed.
_ = _connectionCloseTcs.Task.Exception;
}
_acceptQueue.Writer.TryComplete(exception);
_connectedTcs.TrySetException(exception);
_shutdownTokenSource.Cancel();
Expand Down Expand Up @@ -850,7 +862,6 @@ public async ValueTask DisposeAsync()
Debug.Assert(_connectionCloseTcs.Task.IsCompleted);
_handle.Dispose();
_shutdownTokenSource.Dispose();
_connectionCloseTcs.Task.ObserveException();
_configuration?.Dispose();

// Dispose remote certificate only if it hasn't been accessed via getter, in which case the accessing code becomes the owner of the certificate lifetime.
Expand Down
Loading