Bind the mux listeners exclusively so node cluster cannot share them - #520
Open
CedricConday wants to merge 1 commit into
Open
Bind the mux listeners exclusively so node cluster cannot share them#520CedricConday wants to merge 1 commit into
CedricConday wants to merge 1 commit into
Conversation
srt is built around one process owning one proxy: the mux backend binds a pid-scoped unix socket and each process mints its own proxyAuthToken, with the code noting the token is set "only when this process owns the proxy". The mux front-end contradicted that. It bound with a plain `server.listen(port, '127.0.0.1')`, and under Node's cluster module the primary intercepts listen(), shares one handle across every worker and round robins incoming connections. A sandboxed command spawned by worker A carries A's token in its environment, lands on worker B's proxy, and is answered with 407 Proxy Authentication Required. The failure rate scales as (N-1)/N for N workers, which is how PM2's cluster exec_mode produces intermittent 407s that a retry usually clears. Both loopback listeners now go through loopbackListenOptions(), which sets exclusive, so each worker binds its own port and a child always reaches the proxy whose token it holds. The test drives a real cluster: three workers report one shared port with a plain listen and three distinct ports with an exclusive one. Closes anthropics#458
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
srt is built around one process owning one proxy: the mux backend binds a pid-scoped unix socket and each process mints its own
proxyAuthToken, with the code noting the token is set "only when this process owns the proxy".The mux front-end contradicted that. It bound with a plain
server.listen(port, '127.0.0.1'), and under Node'sclustermodule the primary interceptslisten(), shares one handle across every worker and round robins incoming connections. A sandboxed command spawned by worker A carries A's token in its environment, lands on worker B's proxy, and is answered with407 Proxy Authentication Required. The failure rate scales as(N-1)/Nfor N workers, which is how PM2's clusterexec_modeproduces intermittent 407s that a retry usually clears.Both loopback listeners now go through
loopbackListenOptions(), which setsexclusive, so each worker binds its own port and a child always reaches the proxy whose token it holds.The test drives a real cluster rather than asserting on the shape of the call: three workers report one shared port with a plain listen and three distinct ports with an exclusive one.
typecheckandlint:checkare clean.Closes #458