Copilot commented on code in PR #3930:
URL: https://github.com/apache/thrift/pull/3930#discussion_r4108794276
##########
lib/netstd/Thrift/Transport/Client/THttpTransport.cs:
##########
@@ -237,28 +293,88 @@ private void ConfigureClient(HttpClient httpClient)
public override async Task FlushAsync(CancellationToken
cancellationToken)
{
+ HttpClient httpClient;
+ Stream outputStream;
+ int connectTimeout;
+ lock (_lifecycleLock)
+ {
+ if (!_lifecycleOpen || _httpClient == null || _outputStream ==
null)
+ {
+ throw new
TTransportException(TTransportException.ExceptionType.NotOpen,
+ "The transport has been closed.");
+ }
+ httpClient = _httpClient;
+ outputStream = _outputStream;
+ connectTimeout = _connectTimeout;
+ _flushInProgress++;
+ }
+
+ StreamContent contentStream = null;
+ HttpRequestMessage request = null;
+ HttpResponseMessage response = null;
+ CancellationTokenSource responseReadTimeout = null;
+ Stream inputStream = null;
+ var responseDeadline = Stopwatch.StartNew();
try
{
- _outputStream.Seek(0, SeekOrigin.Begin);
+ outputStream.Seek(0, SeekOrigin.Begin);
- using (var contentStream = new StreamContent(_outputStream))
- {
- contentStream.Headers.ContentType = ContentType ?? new
MediaTypeHeaderValue(@"application/x-thrift");
+ contentStream = new StreamContent(outputStream);
+ contentStream.Headers.ContentType = ContentType ?? new
MediaTypeHeaderValue(@"application/x-thrift");
- var response = (await _httpClient.PostAsync(_uri,
contentStream, cancellationToken)).EnsureSuccessStatusCode();
+ request = new HttpRequestMessage(HttpMethod.Post, _uri)
+ {
+ Content = contentStream
+ };
+
+ response = await httpClient.SendAsync(
+ request,
+ HttpCompletionOption.ResponseHeadersRead,
+ cancellationToken);
Review Comment:
`Close()` can dispose the captured `httpClient` after the lifecycle lock is
released but before this send begins. In that race, `HttpClient.SendAsync`
throws `ObjectDisposedException`, which currently falls through to the generic
catch and is reported as `Unknown` instead of the transport being closed.
Handle it as `NotOpen`, as the new per-call `SendAsync` path already does.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]