-
Notifications
You must be signed in to change notification settings - Fork 2k
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
unusual behavior when proxying websocket to socket.io #50
Comments
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. |
preventing duplicates by checking whether it already has listeners first seems to fix the disconnects as well. I guess heartbeats were being duplicated but only unique heartbeat numbers get processed. I'm not convinced what I've implemented is the proper solution though. |
Not exactly sure what's going on here, but I'll investigate over the weekend. Thanks. |
Hi Charlie, i've tried to reproduce this issue, i got in the console "Error during WebSocket handshake: origin mismatch: http://localhost:8000 != http://localhost" I guess you need to attach the port in both cases, at line 589 and 590, on your Lib: node-http-proxy.js line 586: remoteHost = options.host + (options.port - 80 === 0 ? '' : ':' + options.port); line 589: req.headers.host = remoteHost; line 589: req.headers.host = remoteHost; i tried this with chrome, it diplays the headers like this bellow i've looked into the code from socket.io, i'm convinced, that this should work after these changes. regards |
Hi, again, sorry about my stupid anwser, i tried it, and don't work. :( but this problem was open at issue #34 andyichr commented: i didn't kill both lines, just line 590, and then works.
regards |
Feeback: i tried this with the line 590 commented; after few clicks, i become other error at chrome, i test with both lines commeted, works too, but after few clicks i become an error in node (node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit. 13 May 20:08:47 - [ERROR] Trace regards |
thanks for trying this. it didn't work because you got origin mismatch or data messages were not being duplicated? in the original post i noted that "(you may need to modify node-http-proxy to not change headers)" i believe this issue is unrelated. if you do the same thing but go to the non-proxied path( http://localhost:9000), messages aren't duplicated and connections don't seem to close.
agent emits upgrade for each client connection. in onUpgrade, event listeners are added to the socket and remoteSocket. because agent is the same object across clients, this gets called multiple times per client. if there are 2 connections, connection 1 will have 2 listeners for 'data' and will send duplicates to the remoteSocket.
|
well then you are seeing my issue of duplicate listeners :) |
Hi jfis, i've taked a look again, now i really understood what you mean, ... I had similar problems handling with the method CONNECT, with the proxyjs library, but the objective was something else, sorry, back to the thema... i looked on the code fron http,js (from ry), the http.request function call the function getAgent into http.js, this function build for each connection an ID (host + port) and make this Agent persistent, in this case all clients call the same host + port connection in node througth the same agent ( returned fron the request function), if one or more clients (browser) made connections to a server througth the proxy all of them need his own connection from the proxy to the server, the standard HTTP-Server from Node.JS didn't do that, no with the request function, if we didn't create a new agent explicit with, like example "var myAgent = new http.ClientRequest(options);", it would never work properly. Sorry about all that text, i hope you understand where the problem is. if not, just ask. regards |
@dazagrohovaz Yes, I saw it once I realized that the agent has an eventemitter leak. The problem here is that the proper multiplexing of request-response data doesn't seem possible in the current http.Agent API design because there is no way to map the closure scoped data on the I am going to start seriously considering looking at using a raw TCP proxy for this with my own instantiated HTTPParser. |
the http.Agent API implement a request object from http.ClientRequest, and i think this one it's what you need within http-proxy. You need to implement something like the Agent API, and build for each client-->proxy-connection a proxy-->server-connectoin and preserve it into your app. there is a map for the http.ClientRequest API. http://nodejs.org/docs/v0.4.7/api/http.html#http.ClientRequest regards |
|
@dazagrohovaz @jfis Can you take a look at these repros again after my latest commit? I think I've fixed the event emitter leak by managing the containing the request used to the closure scope of the Will still have to look into the origin mismatch problem |
@indexzero looks good and works for me after getting around the origin mismatch. |
w000!!!! Ok, I'm going to make the origin mismatch thing an option and write some more robust tests here. @dazagrohovaz is that map application on your personal site open source? Seems like a great websocket demo to help benchmark / test against node-http-proxy. |
yes, it is. with some mods, https://github.com/dazagrohovaz/maptail, i don't have commited the changes, but i would do it. |
ready... now , you can clone it. if you want to show the really filename, the line 165 need to be fixed at the index.js file |
@dazagrohovaz Thanks! I will try this out later tonight to see if I've fully resolved the issue |
This should be resolved as of v0.5.3. Let me know if you run into any issues. @dazagrohovaz I couldn't get your maptail working ... if you want to try running your site with node-http-proxy instead of squid that would be appreciated. |
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.
The text was updated successfully, but these errors were encountered: