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

fix: fix EnvHttpProxyAgent for the Node.js bundle #4064

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented Feb 21, 2025

This relates to...

Refs: nodejs/node#57165

Rationale

The Dispatcher needs some prototype methods from lib/api for EnvHttpProxyAgent, otherwise it's incomplete, and throws a TypeError: this[kClient].connect is not a function when EnvHttpProxyAgent is handling requests inside the Node.js bundle.

Changes

Make the Dispatcher prototype complete in the Node.js bundle.

Features

Bug Fixes

Breaking Changes and Deprecations

Status

The Dispatcher needs some methods from lib/api for EnvHttpProxyAgent,
otherwise it's incomplete.
@@ -26,6 +26,9 @@ module.exports.createFastMessageEvent = createFastMessageEvent

module.exports.EventSource = require('./lib/web/eventsource/eventsource').EventSource

const api = require('./lib/api')
Copy link
Member Author

@joyeecheung joyeecheung Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my local testing, it seems only Dispatcher.prototype.connect from the api-connect is missing when I used it for a local proxy. But my testing isn't very thorough, so I am not entirely sure if other methods may also be needed in other paths, in any case it seems a bit of a footgun to leave the Dispatcher partially complete in the Node.js bundle, so I included them all. I am not sure if it's against any principle to include the lib/api parts in the Node.js bundle though. Happy to do a bit of refactoring to move it to somewhere less weird (IMO maybe a better place to put it is to at least assign/implement Dispatcher.prototype.connect in lib/dispatcher/dispatcher, so that the Dispatcher can be used for proxy connection out of the box?)

Locally it increases the bundle size from 610KB+ to 650KB+

Copy link
Member Author

@joyeecheung joyeecheung Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also for context, this is done for the public entry point

Object.assign(Dispatcher.prototype, api)
(and funny enough if seems corepack once used internal paths instead of the public entry point, so there were issues like nodejs/corepack#417 and fixed by nodejs/corepack#451)

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina
Copy link
Member

Can you add a test for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants