Skip to content

Bun proxy-chain library compatibility issues: Connection reset and undefined connectionId #26553

@smmoosavi

Description

@smmoosavi

Description

When using the proxy-chain library with Bun, several critical issues occur that don't happen with Node.js:

  1. Connection Reset: HTTP requests with chunked transfer encoding result in connection reset errors
  2. Undefined connectionId for short-lived connections: The connection identifier is undefined for short-lived connections (like quick HTTPS CONNECT requests), while long-lived connections do get a connectionId but never properly close (see issue 4)
  3. Connection statistics always zero: All byte counters (srcTxBytes, srcRxBytes, trgTxBytes, trgRxBytes) remain at zero despite data transfer
  4. connectionClosed event 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

  1. Clone the repository
  2. Run pnpm install
  3. Open three terminals

Terminal 1:

node waiting-http-server.mjs

Terminal 2:

bun test-proxy.mjs | tee bun-output

Terminal 3:

export https_proxy=http://127.1:4090 http_proxy=http://127.1:4090

curl https://google.com
curl http://127.0.0.1:6000

For 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:6000

Expected Behavior (Node.js)

When running with Node.js (node test-proxy.mjs), the proxy server:

  • Assigns valid connectionId values (including for CONNECT/HTTPS requests)
  • Tracks byte statistics correctly (non-zero values reflecting actual data transfer)
  • Completes chunked transfer responses successfully
  • Fires connectionClosed events 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 undefined for connectionId in prepareRequestFunction for short-lived connections (quick HTTPS requests)
  • Provides a valid connectionId for 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 connectionClosed events - 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-output and bun-output - single curl run
  • node-output-2 and bun-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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions