No way to close proxy/server websocket on client/server error
Created by: glasser
The ws pass does not have any logic to say "if an error occurs on socket
, clean up proxySocket
somehow". And there's no way for you to add that at the application level, because proxySocket
is never passed to application code. This means that in practice, our proxies leak proxySocket
s.
Yes, if socket
is cleanly closed, the pipe
will close proxySocket
as well. But that doesn't occur if socket
errors; for example, if the client disappears from the network (without closing its TCP sockets), socket
will emit error
, and proxySocket
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
: calling socket.unshift(null)
causes socket
to emit end
, which triggers proxySocket.end()
through the pipe. But this is an undocumented use of unshift
. Surprisingly, socket.destroy()
does not seem to cause socket
to emit end
and has no effect on proxySocket
.
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.