Skip to content
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

Proxy agent patch prevents extensions from re-using HTTP connections #173861

Open
JadenSimon opened this issue Feb 8, 2023 · 0 comments
Open
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug proxy Issues regarding network proxies
Milestone

Comments

@JadenSimon
Copy link

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.75.0
  • OS Version: Darwin x64 21.6.0

Steps to Reproduce:

  1. Create a new extension and call https.get or https.request with an agent set to keep connections alive
  2. Change your http.proxySupport setting to override (the default)
  3. Observe that connections are not being reused. This has performance implications as creating sockets is not cheap.

The following code snippet should help demonstrate this problem with notes describing what conditions are needed for connections to persist:

const opt: https.RequestOptions = {
    host: 'example.com',
    port: 443,
    agent: new https.Agent({
        keepAlive: true,
        keepAliveMsecs: 60000,
    }),

    // Explicit headers because something is clobbering the agent's `keepAlive` option
    // Omitting this causes all connections to close regardless of `http.proxySupport`
    headers: { Connection: 'keep-alive' }
}

https.get(opt, r1 => {
    // Without explicit header in `opt` -> `close`
    // With explicit header in `opt` -> `undefined` (implies keep the connection alive)
    console.log('first request connection header ->', r1.headers.connection) 

    // Consume data so we can use the socket again
    r1.on('data', () => {}) 
    r1.on('end', () => {
        https.get(opt, r2 => {
            // `http.proxySupport` set to `override` -> always `false`
            // `http.proxySupport` set to `off` with no header -> `false`
            // `http.proxySupport` set to `off` AND explicit header -> `true`
            console.log('did reuse socket ->', (r2 as any).req.reusedSocket)
        })
    })
}) 

This issue likely originates from here. I'm not entirely sure why an explicit header is needed, but it might be because the proxy patch bypasses logic that would normally set the header. This line appears to be called even when http.proxySupport is set to off.

justinmk3 pushed a commit to aws/aws-toolkit-vscode that referenced this issue Nov 14, 2023
Problem:
[microsoft/vscode#173861](microsoft/vscode#173861)

Solution:
Inject http agent only for the GenerateCompletions API, do this per IDE session.

Tested and verified:
1. This inject won't happen for any other API calls. It only applies to
   GenerateCompletions API when user is NOT using `http.proxy` vscode feature.
2. No regression found with Toolkit features or CodeWhisperer features.
3. Regardless of user VSC proxy setting `http.proxySupport`, it still enables HTTP connection reuse.
4. Tested in AWS Cloud9.
@chrmarti chrmarti added bug Issue identified by VS Code Team member as probable bug proxy Issues regarding network proxies labels Dec 5, 2023
@chrmarti chrmarti added this to the December 2023 milestone Dec 5, 2023
@chrmarti chrmarti modified the milestones: December / January 2024, February 2024 Jan 25, 2024
@chrmarti chrmarti modified the milestones: February 2024, March 2024 Feb 21, 2024
@chrmarti chrmarti modified the milestones: March 2024, April 2024 Mar 27, 2024
@chrmarti chrmarti modified the milestones: April 2024, May 2024 Apr 25, 2024
@chrmarti chrmarti modified the milestones: May 2024, June 2024 May 28, 2024
@chrmarti chrmarti modified the milestones: June 2024, On Deck Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug proxy Issues regarding network proxies
Projects
None yet
Development

No branches or pull requests

2 participants