Error: socket hang up in Node 4.2.1 (but not 0.12)
See original GitHub issueHello!
I’m trying to debug this issue: https://github.com/blakmatrix/node-zendesk/issues/110
Having looked into it a bit, it looks like it is a bug in request
—the only alternative could be that the API I’m making requests to is rejecting the useragent with node/4.2.1
in and not the one with node/0.12
in.
request
is being passed the same data in both versions of Node, and is being called multiple times. It never fails on the first time it is called, it usually fails between the third and sixth times—it’s being passed only slightly different data (page numbers), but sporadically fails.
This is some sample data that sometimes succeeds and sometimes fails:
{ stores:
{ defaults:
Literal {
type: 'literal',
store: [Object],
mtimes: {},
readOnly: true,
loadFrom: null,
logicalSeparator: ':' } },
sources: [],
headers:
{ 'Content-Type': 'application/json',
Accept: 'application/json',
'User-Agent': 'node-zendesk/1.1.5 (node/4.2.1)',
Authorization: 'Basic [redacted]' },
uri: 'https://[redacted].zendesk.com/api/v2/search.json?page=3&query=checkout-failure',
method: 'GET' }
And request is being given the following defaults:
{ jar: RequestJar { _jar: CookieJar { store: { idx: {} } } },
encoding: null,
timeout: 240000,
proxy: null,
secureOptions: 134217728 }
The following error is (eventually) thrown:
Error: socket hang up
at createHangUpError (_http_client.js:203:15)
at TLSSocket.socketOnEnd (_http_client.js:288:23)
at emitNone (events.js:72:20)
at TLSSocket.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:903:12)
at doNTCallback2 (node.js:439:9)
at process._tickCallback (node.js:353:17)
What could be causing this? Is this a bug in request, or is there something wrong with how we’re calling it?
I’m too far deep into a library I am unfamiliar with to make a stripped down test case. If necessary, I can make one—wanted to check it wasn’t something obvious before investing the time, first, though.
Here is where request is initiated: https://github.com/blakmatrix/node-zendesk/blob/master/lib/client/client.js#L35-L41
Here is where it is called: https://github.com/blakmatrix/node-zendesk/blob/master/lib/client/client.js#L100-L102
Help would be much appreciated, thanks!
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:15
Did you use a keepAlive socket? If the server requires a keep-alive connection , and your headers doesn’t include the keep-alive option and it will return an socket hang up error. and the most important is , In node 0.12, setting ‘Connection’: ‘Keep-Alive’ property in http option will work. But in node 4.0 or above, if you would like to use keep-alive connection, you have to create an agent and set its keepAlive property to true. So,in this situation, the same code will work on 0.12 but won’t work anymore on 4.0. I hope this will help you .
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.