Skip to content

Websockets dont work with a router #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tarang opened this issue May 12, 2013 · 11 comments
Closed

Websockets dont work with a router #421

Tarang opened this issue May 12, 2013 · 11 comments

Comments

@Tarang
Copy link

Tarang commented May 12, 2013

I'm not sure if this is a bug or not but websockets wont work with a proxy table e.g

var options = {
router: {
    'a.websterten.com': '127.0.0.1:150',
    'b.websterten.com' : '127.0.0.1:151',
}
};

var server = httpProxy.createServer(options);

It works fine proxying web requests. But websockets don't work. If I access the site directly it does work (with websockets)

I also unsuccessfully tried adding in

server.on('upgrade', function (req, socket, head) {
    server.proxy.proxyWebSocketRequest(req, socket, head);
});

It also looks like server.on('upgrade doesn't fire. In addition, even without the above event. If there are attempts to use websockets (after a while). The below error will appear:

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at Socket.EventEmitter.addListener (events.js:160:15)
    at Socket.Readable.on (_stream_readable.js:663:33)
    at Socket.EventEmitter.once (events.js:179:8)
    at TCP.onread (net.js:527:26)

After a while it will run out of memory and crash.

@glasser
Copy link
Contributor

glasser commented May 13, 2013

See #402 (comment)

@adrai
Copy link

adrai commented Jun 4, 2013

I just tried to update from 0.8.5 to 0.10.2 and I see the same issue... :-(

0.8.5 ok
0.10.2 nok

@christian-fei
Copy link

DId you guys figure out a solution somehow? Still having troubles proxying ws

@Rush
Copy link
Contributor

Rush commented Sep 3, 2013

I would love to know the solution as well ...

@christian-fei
Copy link

Hey @RushPL I found that the only solution atm is to use nginx to proxy stuff.
WebSockets work just fine.
If you need further help just ask

@Rush
Copy link
Contributor

Rush commented Sep 3, 2013

Thanks a lot. Actually I found out about nvm which stands for Node Version Manager. I was able to run the node-http-proxy binary on the older node version and still have the newest node for rest of my stuff. I have also tried the 0.10.x branch but it didn't work at all.

@christian-fei
Copy link

Yep, same here. tried the http-proxy of nodejitsu, but no luck with node 0.10.x, so I just switched to nginx, where 0.10.x work just fine

@raintonr
Copy link

+1 please.

In the meantime, say I did want to use http-proxy for routing with WS. That seems impossible right now so will have to resort to nginx or not bother with WS.

Can anyone comment on the memory footprint of nginx versus a routing http-proxy script? Nginx would be setup to route and not cache or do anything else fancy.

@Rush
Copy link
Contributor

Rush commented Dec 11, 2013

You can use old node-http-proxy with Node.JS 0.8 - it works fine with web sockets. I have observed only negligible memory usage on the proxy's part but I am not running thousands of web sockets so your mileage may vary.

You can get Node 0.8 very easily with Node Version Manager.

@yawnt
Copy link
Contributor

yawnt commented Dec 18, 2013

hi!
@RushPL
if you're having other issues with the caronte branch and websockets, you can open up an issue and i'll have a look!
please provide a test case as well :)

closing this issue since it refers to a dropped component (router) and the 0.8.x branch

@yawnt yawnt closed this as completed Dec 18, 2013
@raintonr
Copy link

router has been dropped? I assume that is because there is another node module that can be integrated with http-proxy to give the same function?

If someone could put a quick link/note here to explain how that can/should be done that would be great.

Sorry - I'm no expert in any of this or would try to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants