未验证 提交 edfca3c2 编写于 作者: C campersau 提交者: GitHub

Pass CancellationToken to Http2Connection SetupAsync (#70906)

* Pass cancellation token to Http2Connection SetupAsync

* PR feedback
上级 ef293899
......@@ -174,7 +174,7 @@ public Http2Connection(HttpConnectionPool pool, Stream stream)
private object SyncObject => _httpStreams;
public async ValueTask SetupAsync()
public async ValueTask SetupAsync(CancellationToken cancellationToken)
{
try
{
......@@ -208,7 +208,7 @@ public async ValueTask SetupAsync()
BinaryPrimitives.WriteUInt32BigEndian(_outgoingBuffer.AvailableSpan, windowUpdateAmount);
_outgoingBuffer.Commit(4);
await _stream.WriteAsync(_outgoingBuffer.ActiveMemory).ConfigureAwait(false);
await _stream.WriteAsync(_outgoingBuffer.ActiveMemory, cancellationToken).ConfigureAwait(false);
_rttEstimator.OnInitialSettingsSent();
_outgoingBuffer.Discard(_outgoingBuffer.ActiveLength);
......@@ -217,6 +217,13 @@ public async ValueTask SetupAsync()
catch (Exception e)
{
Dispose();
if (e is OperationCanceledException oce && oce.CancellationToken == cancellationToken)
{
// Note, AddHttp2ConnectionAsync handles this OCE separately so don't wrap it.
throw;
}
throw new IOException(SR.net_http_http2_connection_not_established, e);
}
......
......@@ -1561,11 +1561,17 @@ private async ValueTask<Http2Connection> ConstructHttp2ConnectionAsync(Stream st
Http2Connection http2Connection = new Http2Connection(this, stream);
try
{
await http2Connection.SetupAsync().ConfigureAwait(false);
await http2Connection.SetupAsync(cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
// Note, SetupAsync will dispose the connection if there is an exception.
if (e is OperationCanceledException oce && oce.CancellationToken == cancellationToken)
{
// Note, AddHttp2ConnectionAsync handles this OCE separatly so don't wrap it.
throw;
}
throw new HttpRequestException(SR.net_http_client_execution_error, e);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册