Socket Reuse Can Cause Multiple CONNECT Requests on Same TCP Connection
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- nodejs, typescript
- Ambito
- networking
Direzione di ricerca
Start with the socket-reuse comment near chain.js:52 and the httpAgent option that prepareRequestFunction accepts, then check how anonymizeProxy builds its upstream connection. Reproducing needs an upstream proxy and a tcpdump capture of repeated CONNECT requests on one socket. The open question is whether reuse is a bug or expected, so a maintainer decision on that comes before any change.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
When using ProxyChain without specifying a custom httpAgent in prepareRequestFunction or using anonimyzeProxy, Node.js's default HTTP agent (which has keepAlive: true) may reuse TCP sockets for multiple CONNECT requests to the upstream proxy. This can cause intermittent connection failures when using proxy-chain to forward requests to an upstream proxy server.
Background
According to RFC 9110 Section 9.3.6:
A tunnel is closed when a tunnel intermediary detects that either side has closed its connection: the intermediary MUST attempt to send any outstanding data that came from the closed side to the other side, close both connections, and then discard any remaining data left undelivered.
After a successful CONNECT response (200), the TCP connection becomes a tunnel and should be treated as opaque to HTTP semantics. I may be misunderstanding the specification, but it seems that sending another CONNECT request through an already-established tunnel might violate this principle.
Reproducing
This issue was initially observed when using anonymizeProxy(), which creates a ProxyChain server that forwards to upstream proxies.
This appears more frequently on slower machines where there's more temporal overlap between requests.
import ProxyChain from "proxy-chain";
import puppeteer from "puppeteer";
const proxyUrl = await ProxyChain.anonymizeProxy(
"http://user:[email protected]:8080"
);
const browser = await puppeteer.launch({
args: [`--proxy-server=${proxyUrl}`],
});
const page = await browser.newPage();
await page.goto("https://www.github.com/");
// Intermittent failures observed here
We then used tcpdump to capture traffic and observe socket re-use.
Workaround
The issue can be resolved by providing a custom httpAgent with keepAlive: false:
import http from 'http';
const noReuseAgent = new http.Agent({
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 0,
});
const server = new ProxyChain.Server({
prepareRequestFunction: () => ({
upstreamProxyUrl: "http://user:[email protected]:8080",
requestAuthentication: false,
httpAgent: noReuseAgent, // Prevents socket reuse
}),
});
With this configuration, each CONNECT request gets a fresh TCP connection to the upstream proxy, eliminating the intermittent failures.
Questions
I'd appreciate clarification on a few points:
-
Is this expected behavior? The comment in
chain.js:52mentions "Socket can be re-used by multiple requests" which suggests awareness of socket reuse, but I'm unsure if this refers to regular HTTP requests or CONNECT tunnels. -
Is my interpretation of the HTTP spec correct? I may be misunderstanding how CONNECT tunnels should work in the context of HTTP connection pooling.
-
Is socket reuse for CONNECT requests a common practice? Perhaps this behavior works fine with some upstream proxies and only certain implementations reject it.
- Lingua principale
- TypeScript
- Stelle
- 1k
- Fork
- 167
- Merge medio
- 16h 22m
- PR unite (30g)
- 16
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apify/proxy-chain
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
apify/proxy-chain#635 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
apify/proxy-chain#634 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 12/100
apify/proxy-chain#633 ·
I maintainer di solito rispondono entro 1 giorno
-
good first issue low priority t-unblocking tech roadmap
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
apify/proxy-chain#632 ·
I maintainer di solito rispondono entro 1 giorno
-
low priority t-unblocking tech roadmap
Difficoltà 3/5 Mezza giornata Idoneità per principianti 28/100
apify/proxy-chain#631 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di apify/proxy-chain
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
vercel/streamdown#673 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
docs(stream-protocol): document messageMetatadata on start/finish and the message-metadata chunkApertafactory-active task-identify-harness-labels-done task-identify-issue-type-done
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
vercel/ai#23375 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
agilepathway/label-checker#721 ·
I maintainer di solito rispondono entro 1 giorno
-
CLI Empathy needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
chromaui/chromatic-cli#1524 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno