Skip to content

Commit

Permalink
Sync Dispose in H3Stream waits for read and write as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ManickaP committed Sep 12, 2023
1 parent 8d22715 commit f6261e9
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,25 @@ public void Dispose()
{
_disposed = true;
AbortStream();
// We aborted both sides, thus both task should unblock and should be finished before disposing the QuicStream.
WaitUnfinished(_sendRequestTask);
WaitUnfinished(_readResponseTask);
_stream.Dispose();
DisposeSyncHelper();
}

static void WaitUnfinished(Task? task)
{
if (task is not null && !task.IsCompleted)
{
try
{
task.GetAwaiter().GetResult();
}
catch // Exceptions from both tasks are logged via _connection.LogException() in case they're not awaited in SendAsync, so the exception can be ignored here.
{ }
}
}
}

private void RemoveFromConnectionIfDone()
Expand Down

0 comments on commit f6261e9

Please sign in to comment.