-
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
No way to close proxy/server websocket on client/server error #559
Comments
Here's my thought. There are two ways we could go. Either http-proxy should itself take care of this, by reacting to 'error' on I think the former is probably the way to go. First of all, it's more or less necessary to do this error handling, and we shouldn't make it easy for users to accidentally cause a leak. Secondly, it's already the case that the ws Working on a PR now. One thing that confuses me: it looks like there's a straight-up bug in the stream pass: it takes its server and head arguments in a different order from how they are passed in! Is there a test suite that should be catching this? (Our current production use of http-proxy/caronte is based on an old commit from back when caronte used EventEmitter2 which doesn't have this issue.) |
OK, see #560 for the "one thing that confuses me". I'm going to build a PR on top of that PR to fix this issue. |
Fixes http-party#559, which contains a full reproduction recipe.
#561 is the PR for this issue. Note that even with this PR, it's most likely the case that most users will also want to run proxy.on('error', function (err, req, socket) {
socket.end();
}); which we've had in our code forever. That cleans up the other direction: errors in outgoing should close incoming. You might want to add that to the ws stream pass too. The main difference is that users actually can write the above code with the current module, whereas they can't write the code that's being added in this commit. (Also, you could imagine wanting to have different error handling behavior for this case: for example, maybe the proxy should instead to try reconnect to another backend server while keeping the client's socket alive.) |
The ws pass does not have any logic to say "if an error occurs on
socket
, clean upproxySocket
somehow". And there's no way for you to add that at the application level, becauseproxySocket
is never passed to application code. This means that in practice, our proxies leakproxySocket
s.Yes, if
socket
is cleanly closed, thepipe
will closeproxySocket
as well. But that doesn't occur ifsocket
errors; for example, if the client disappears from the network (without closing its TCP sockets),socket
will emiterror
, andproxySocket
will never be cleaned up.See https://github.com/glasser/proxy-error-handling for a reproduction of this issue; it is trivially reproduced if you have a second machine (such as a recent Android/iPhone) that can load a web page served from your workstation and then disconnect itself from the network.
I've found a hacky way to close
proxySocket
: callingsocket.unshift(null)
causessocket
to emitend
, which triggersproxySocket.end()
through the pipe. But this is an undocumented use ofunshift
. Surprisingly,socket.destroy()
does not seem to causesocket
to emitend
and has no effect onproxySocket
.Node 0.10.22, but I don't believe there are any net or streams changes in 0.10.23 or 0.10.24.
See also meteor/meteor#1769.
The text was updated successfully, but these errors were encountered: