FG
📡 Networking

unusual behavior when proxying websocket to socket.io

Freshalmost 15 years ago
Mar 14, 20260 views
Confidence Score88%
88%

Problem

I'm not really sure how to explain so I whipped up some code to demonstrate. https://gist.github.com/967964 please run that, then open 3 (console-supporting) browsers at http://localhost:8000 (i hope to find something to simulate in the future) hit send in each (you may need to modify node-http-proxy to not change headers) console will log msgs rcvd from server. then open 3 more browsers at http://localhost:9000 (no proxy) hit send in each notice the output is different. also, the server output is different. when proxied, messages are duplicated for client X depending on the number of clients connected after X. also, connections disconnect after some time when proxied while they remain open indefinitely when not proxied. [code block]

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate1 verificationLast verified Mar 14, 2026

Solution: unusual behavior when proxying websocket to socket.io

Low Risk

The disconnects happen on the heartbeat timeout. Not sure what isn't passed through node-http-proxy yet. The duplicate messages happen because onUpgrade() gets called every time any client connects which adds duplicate listeners. It seems agent (of _getAgent) is the same object for all connections. onUpgrade is invoked in a listener for the agent 'upgrade' event.

84

Trust Score

1 verification

100% success
  1. 1

    The disconnects happen on the heartbeat timeout. Not sure what isn't passed thro

    The disconnects happen on the heartbeat timeout. Not sure what isn't passed through node-http-proxy yet.

  2. 2

    The duplicate messages happen because onUpgrade() gets called every time any cli

    The duplicate messages happen because onUpgrade() gets called every time any client connects which adds duplicate listeners. It seems agent (of _getAgent) is the same object for all connections. onUpgrade is invoked in a listener for the agent 'upgrade' event.

Validation

Resolved in http-party/node-http-proxy GitHub issue #50. Community reactions: 0 upvotes.

Verification Summary

Worked: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

proxyhttpnode.js