-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Description
When using the proxy-chain library with Bun, several critical issues occur that don't happen with Node.js:
- Connection Reset: HTTP requests with chunked transfer encoding result in connection reset errors
- Undefined
connectionIdfor short-lived connections: The connection identifier isundefinedfor short-lived connections (like quick HTTPS CONNECT requests), while long-lived connections do get aconnectionIdbut never properly close (see issue 4) - Connection statistics always zero: All byte counters (srcTxBytes, srcRxBytes, trgTxBytes, trgRxBytes) remain at zero despite data transfer
connectionClosedevent never fired: The event is never called, causing long-lived connections to accumulate indefinitely in the active connections list
Reproduction
I've created a minimal reproduction repository:
Repository: https://github.com/smmoosavi/bun-proxy-chain-bug
Steps to Reproduce
- Clone the repository
- Run
pnpm install - Open three terminals
Terminal 1:
node waiting-http-server.mjsTerminal 2:
bun test-proxy.mjs | tee bun-outputTerminal 3:
export https_proxy=http://127.1:4090 http_proxy=http://127.1:4090
curl https://google.com
curl http://127.0.0.1:6000For a clearer demonstration of connection accumulation, run the curl commands twice:
export https_proxy=http://127.1:4090 http_proxy=http://127.1:4090
curl https://google.com ; curl http://127.0.0.1:6000
# wait a few seconds
curl https://google.com ; curl http://127.0.0.1:6000Expected Behavior (Node.js)
When running with Node.js (node test-proxy.mjs), the proxy server:
- Assigns valid
connectionIdvalues (including for CONNECT/HTTPS requests) - Tracks byte statistics correctly (non-zero values reflecting actual data transfer)
- Completes chunked transfer responses successfully
- Fires
connectionClosedevents when connections are closed
The curl request completes successfully with output:
0
1
2
3
Actual Behavior (Bun)
When running with Bun (bun test-proxy.mjs), the proxy server:
- Provides
undefinedforconnectionIdinprepareRequestFunctionfor short-lived connections (quick HTTPS requests) - Provides a valid
connectionIdfor long-lived connections, but these connections never close - Reports all connection statistics as zero (srcTxBytes, srcRxBytes, trgTxBytes, trgRxBytes all remain 0)
- Causes "Connection Reset" error on the client side for chunked responses
- Never fires
connectionClosedevents - long-lived connections accumulate in the active list (e.g., [0], then [0, 1], then [0, 1, 2]...)
The curl request fails with:
Connection Reset%
Additional Context
The test setup uses a simple HTTP server with chunked transfer encoding (waiting-http-server.mjs) to expose the connection handling issues. The proxy server (test-proxy.mjs) is minimal and only logs connection details without any complex logic.
Output files are included in the repository:
node-outputandbun-output- single curl runnode-output-2andbun-output-2- double curl run (clearly shows connection accumulation in Bun)
According to Bun's Node.js compatibility documentation:
If a package works in Node.js but doesn't work in Bun, we consider it a bug in Bun. Please open an issue and we'll fix it.
Since proxy-chain works correctly in Node.js but fails in Bun, this qualifies as a Bun bug per their own criteria.
Environment
- Bun version: 1.3.7
- Node.js version: v22.14.0 (for comparison)
- OS: Ubuntu 24.04.3 LTS (Linux 6.14.0-37-generic x86_64 x86_64)
- proxy-chain version: ^2.7.1