Copilot commented on code in PR #3930:
URL: https://github.com/apache/thrift/pull/3930#discussion_r4109059864


##########
lib/netstd/Thrift/Transport/Client/THttpTransport.cs:
##########
@@ -118,27 +135,49 @@ public int ConnectTimeout
         public override Task OpenAsync(CancellationToken cancellationToken)
         {
             cancellationToken.ThrowIfCancellationRequested();
+            lock (_lifecycleLock)
+            {
+                if (!_lifecycleOpen || _httpClient == null)
+                {
+                    throw new 
TTransportException(TTransportException.ExceptionType.NotOpen,
+                        "The transport has been closed.");
+                }
+            }
             return Task.CompletedTask;
         }
 
         public override void Close()
         {
-            if (_inputStream != null)
+            List<THttpPerCallTransport> transports;
+            CancellationTokenSource lifecycleCancellation;
+            lock (_lifecycleLock)
             {
-                _inputStream.Dispose();
-                _inputStream = null;
-            }
+                _lifecycleOpen = false;
+                transports = new 
List<THttpPerCallTransport>(_perCallTransports);
+                _perCallTransports.Clear();
+                lifecycleCancellation = _lifecycleCancellation;
+                _lifecycleCancellation = null;
 
-            if (_outputStream != null)
-            {
-                _outputStream.Dispose();
-                _outputStream = null;
+                _inputStream?.Dispose();
+                _inputStream = null;
+                if (_flushInProgress == 0)
+                {
+                    _outputStream?.Dispose();
+                    _outputStream = null;
+                }

Review Comment:
   When `Close()` runs during an active flush, this branch deliberately leaves 
`_outputStream` published. A subsequent `WriteAsync` does not check 
`_lifecycleOpen`, so it can successfully append to the same stream after 
`Close()` has returned, potentially mutating the in-flight HTTP request. Clear 
the field immediately (while letting the active flush retain and dispose its 
local stream) and make `WriteAsync` capture the stream only after a lifecycle 
check under this lock.



-- 
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]

Reply via email to