- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.2k
Prevent returning disposed HTTP/1.1 connections to the pool #112383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            antonfirsov
  merged 2 commits into
  dotnet:main
from
antonfirsov:CompleteResponse-Disposed
  
      
      
   
  Feb 11, 2025 
      
    
                
     Merged
            
            Prevent returning disposed HTTP/1.1 connections to the pool #112383
                    antonfirsov
  merged 2 commits into
  dotnet:main
from
antonfirsov:CompleteResponse-Disposed
  
      
      
   
  Feb 11, 2025 
              
            Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    | /azp run runtime-libraries stress-http | 
| Azure Pipelines successfully started running 1 pipeline(s). | 
              
                    MihaZupan
  
              
              approved these changes
              
                  
                    Feb 11, 2025 
                  
              
              
            
            
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
        
          
                src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs
          
            Show resolved
            Hide resolved
        
      
  This was referenced Feb 11, 2025 
      
      
  
  Open
  
      
  
  Closed
  
              
                    ManickaP
  
              
              approved these changes
              
                  
                    Feb 11, 2025 
                  
              
              
            
            
| /azp run runtime-libraries-coreclr outerloop | 
| Azure Pipelines successfully started running 1 pipeline(s). | 
| CI failures are unrelated. | 
    
  grendello 
      added a commit
        to grendello/runtime
      that referenced
      this pull request
    
      Feb 12, 2025 
    
    
      
  
    
      
    
  
* main: [Android] Run CoreCLR functional tests on Android (dotnet#112283) [LoongArch64] Fix some assertion failures for Debug ILC building Debug NativeAOT testcases. (dotnet#112229) Fix suspicious code fragments (dotnet#112384) `__ComObject` doesn't support dynamic interface map (dotnet#112375) Native DLLs: only load imported DLLs from System32 (dotnet#112359) [main] Update dependencies from dotnet/roslyn (dotnet#112314) Update SVE instructions that writes to GC regs (dotnet#112389) Bring up android+coreclr windows build. (dotnet#112256) Never use heap for return buffers (dotnet#112060) Wait to complete the test before releasing the agile reference. (dotnet#112387) Prevent returning disposed HTTP/1.1 connections to the pool (dotnet#112383) Fingerprint dotnet.js if writing import map to html is enabled (dotnet#112407) Remove duplicate definition of CORECLR_HOSTING_API_LINKAGE (dotnet#112096) Update the exception message to reflect current behavior. (dotnet#112355) Use enum for frametype not v table (dotnet#112166) Enable AltJits build for LoongArch64 and RiscV64 (dotnet#110282) Guard members of MonoType union & fix related bugs (dotnet#111645) Add optional hooks for debugging OpenSSL memory allocations (dotnet#111539) JIT: Optimize struct parameter register accesses in the backend (dotnet#110819) NativeAOT: Cover more opcodes in type preinitializer (dotnet#112073)
  
      Sign up for free
      to subscribe to this conversation on GitHub.
      Already have an account?
      Sign in.
  
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Fixes #31254
Fixes #110577
There are race conditions in HTTP 1.1 response stream reading methods that may prevent the exceptional termination of those methods despite cancellation callbacks firing and disposing the connection, see the discussion starting with #31254 (comment).
As a result, these methods may call
CompleteResponsereturning the disposed connection to the pool.This is a minimal fix for the mentioned issue, but I agree with @MihaZupan that we should rework the HTTP/1.1 cancellation, making sure to forward the CancellationTokens down to the underlying stream instead of relying on CancellationTokenRegistration + Dispose. In case we take this PR, I'm planning to open a new issue to track that work.