hoxy
hoxy copied to clipboard
socket error not handled
Not sure what the reason for it is but I sometimes get the error { [Error: socket hang up] code: 'ECONNRESET' } but I cannot simply reproduce it.
I have a trace of when it happens, in this case I'm running NODE_DEBUG=net so it logs a lot, see here:
https://gist.github.com/editedredx/94e3ed4fdfadf8cf6418
Running windows and the request at the top is a https POST Firefox makes automatically every X minutes. This often seems to be the culprit however it looks like some other requests can also trigger it.
Ideally I need an implementation of stream.Readable which deliberately fails and causes this exact same socket hang up/ECONNRESET error, which I could plug into a unit test. Then I can go about fixing it in a controlled way and protect against similar future errors. I've tinkered around with it but haven't gotten it working yet.
Haven't been able to produce an exact failing test so far. I have found a request that seems to crash hoxy every time.
the request is: GET https://addons.mozilla.org/en-US/firefox/addons/buttons.js
with headers:
Host: addons.mozilla.org
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Although I don't think they matter for the crash. the response is 200 Connection Established with response headers:
Connection: close
Content-Length: 178
Content-Type: text/html
Date: Mon, 05 Oct 2015 08:08:16 GMT
Location: https://addons.cdn.mozilla.net/en-US/firefox/addons/buttons.js
Server: nginx
x-backend-server: web7
Although I don't think they matter either, what I do think matters is the response code 200 Connection Established, when not using a proxy I get 301 moved permanently and the headers are the same.
With and without proxy both return an empty response body.
Yeah I think it's lower level like an abruptly closed network connection maybe? I've seen it happen for example closing a browser tab that has an in-flight request.
I'm having similar issue when proxying to a page that uses websockets. hoxy for pages without websockets look stable and reliable, as soon as websockets are in the game, after a couple of minutes I get:
Error: socket hang up
at createHangUpError (_http_client.js:250:15)
at Socket.socketOnEnd (_http_client.js:342:23)
at emitNone (events.js:91:20)
at Socket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:926:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
funny enough, when I try to run in NODE_DEBUG=net (or http), I see the errors, but the app doesn't crash and carries on...
this is the error in net debug mode
NET 9169: destroy { Error: socket hang up
at TLSSocket.<anonymous> (_tls_wrap.js:816:25)
at emitOne (events.js:101:20)
at TLSSocket.emit (events.js:188:7)
at Socket._handle.close (net.js:492:12)
at Socket.g (events.js:286:16)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at TCP._handle.close [as _onclose] (net.js:492:12) code: 'ECONNRESET' }
the proxy solution I'm trying to implement can be found here: https://github.com/aurainfosec/node-proxy-replay
I'm running into a similar issue
Just once in a while, browse a few pages
events.js:163
throw er; // Unhandled 'error' event
^
Error: socket hang up
at createHangUpError (_http_client.js:302:15)
at Socket.socketOnEnd (_http_client.js:394:23)
at emitNone (events.js:91:20)
at Socket.emit (events.js:188:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
~~Also on windows (seems to be windows only, ran the same thing on mac and it was fine)~~ Happens both on windows and mac
I just commented on the related issue: https://github.com/greim/hoxy/pull/93#issuecomment-417692187.
Hope it's helpful somehow