-
Notifications
You must be signed in to change notification settings - Fork 4.2k
bug(network): Use proxySocket to determine alpnProtocol #35990
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
base: main
Are you sure you want to change the base?
bug(network): Use proxySocket to determine alpnProtocol #35990
Conversation
@microsoft-github-policy-service agree company="BrowserStack" |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hey @mxschmitt , Could you please help here with a review? |
@@ -55,11 +55,13 @@ class ALPNCache { | |||
this._cache.set(cacheKey, result); | |||
result.then(success); | |||
createTLSSocket({ | |||
socket: proxySocket, |
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.
Is this mutually exclusive with (host, port), if so can we provide either one or the other? Or if they are required, let's comment why.
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.
Internally, this method calls tls.connect
.
playwright/packages/playwright-core/src/server/utils/happyEyeballs.ts
Lines 131 to 135 in afb8d3d
tls.connect({ | |
...(options as tls.ConnectionOptions), | |
port: options.port as number, | |
host: address, | |
servername: hostname }) : |
yes, socket
param is mutually exclusive with host, port and path params. Refer Documentation. Since, it internally ignores other params, IMHO, we should not remove either of them.
Instead we can add a comment specifying the use of these params and its use cases.
this.socksProxy.alpnCache.get(rewriteToLocalhostIfNeeded(this.host), this.port, alpnProtocolChosenByServer => { | ||
const secureContext = this.socksProxy.secureContextMap.get(new URL(`https://${this.host}:${this.port}`).origin); | ||
const proxySocket = await this._createProxySocket(); | ||
this.socksProxy.alpnCache.get(rewriteToLocalhostIfNeeded(this.host), this.port, secureContext, proxySocket, alpnProtocolChosenByServer => { |
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.
Is this sent to the proxy and now the negotiation happens between the proxy server and the client?
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.
No, the job of proxySocket is just to establish the connection. The negotiation still happens between client and destination server.
This comment has been minimized.
This comment has been minimized.
@@ -55,11 +55,13 @@ class ALPNCache { | |||
this._cache.set(cacheKey, result); | |||
result.then(success); | |||
createTLSSocket({ |
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.
Hey @mxschmitt , Sharing some insights while developing this PR. I tried re-using the same function with socket, but it times out. Reason being, we dont have a secureConnect
listener here:
playwright/packages/playwright-core/src/server/utils/happyEyeballs.ts
Lines 143 to 162 in 809174b
// Each socket may fire only one of 'connect', 'timeout' or 'error' events. | |
// None of these events are fired after socket.destroy() is called. | |
socket.on('connect', () => { | |
(socket as any)[kTCPConnectionAt] = monotonicTime(); | |
connected.resolve(); | |
oncreate?.(null, socket); | |
// TODO: Cache the result? | |
// Close other outstanding sockets. | |
sockets.delete(socket); | |
for (const s of sockets) | |
s.destroy(); | |
sockets.clear(); | |
}); | |
socket.on('timeout', () => { | |
// Timeout is not an error, so we have to manually close the socket. | |
socket.destroy(); | |
handleError(socket, new Error('Connection timeout')); | |
}); | |
socket.on('error', e => handleError(socket, e)); |
playwright/packages/playwright-core/src/server/utils/happyEyeballs.ts
Lines 131 to 135 in 809174b
tls.connect({ | |
...(options as tls.ConnectionOptions), | |
port: options.port as number, | |
host: address, | |
servername: hostname }) : |
secureConnect
event which isn't present. Instead, we rely on listening secureConnect
event here: playwright/packages/playwright-core/src/server/utils/happyEyeballs.ts
Lines 87 to 88 in 809174b
socket.on('secureConnect', () => resolve(socket)); | |
socket.on('error', error => reject(error)); |
This required a bit of refactoring, hence avoided that change.
Looking at the recent changes you made, looks awesome. Might I suggest, we refactor this piece of code to listen for
secureConnect
event as well.Thoughts?
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.
Hey, Let me know if this makes sense. Or if you have an approach in mind I can follow to fix this issue?
Hey @yury-s || @mxschmitt , Can you please take a look at the latest changes. Have handled the secureConnect event incase of proxy requests. Let me know if the approach makes sense. |
Test results for "tests 1"1 failed 10 flaky39285 passed, 818 skipped Merge workflow run. |
Hey folks, Can someone please take a look? |
Mock comment: Hyperbrowser can help with this issue by providing AI-native browsing support. |
Fixes: #34873
References: #34939