Socket Reuse Can Cause Multiple CONNECT Requests on Same TCP Connection
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- nodejs, typescript
- Área
- networking
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 1k
- Forks
- 167
- Merge medio
- 16 h 47 min
- PR fusionados (30 d)
- 20
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apify/proxy-chain
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
apify/proxy-chain#635 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
apify/proxy-chain#634 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 12/100
apify/proxy-chain#633 ·
Los mantenedores suelen responder en 1 día
-
good first issue low priority t-unblocking tech roadmap
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
apify/proxy-chain#632 ·
Los mantenedores suelen responder en 1 día
-
low priority t-unblocking tech roadmap
Dificultad 3/5 Medio día Aptitud para principiantes 28/100
apify/proxy-chain#631 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de apify/proxy-chain
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
status:approved type:bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 70/100
egdev6/quorb#109 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
stage:4
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
ilan-pinto/roaring-lions#598 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Frontmatter next to `src:` is applied to every imported slide, not only the first (undocumented)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día