You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
Https.request sporadically fails with "Cannot call method 'emit' of undefined" error #670
This is observed with node 0.4.0 on cygwin. I am calling https.request to connect to a server, and sporadically am experiencing the following exception:
node.js:116
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot call method 'emit' of undefined
at CleartextStream. (http.js:1135:9)
at CleartextStream.emit (events.js:42:17)
at Socket.onerror (tls.js:809:17)
at Socket.emit (events.js:42:17)
at Array. (net.js:799:27)
at EventEmitter._tickCallback (node.js:108:26)
I did some debugging and I believe that what is happening is that the server I am connecting to is sometimes not doing an orderly shutdown of the SSL conversation. This is causing an ECONNABORTED error at my node client. The catch is that the response has already been received and hence some cleanup of the node socket structure has already occurred within node, leaving it with nothing to emit the error event to.
At a code level, take a look at http.js. The crash I am seeing is happening at line 1148, where the code tries to emit the error event on the request object, which is null. It is null because, prior to the error event being emitted on the socket, the listener for the end event on the response (line 1244) was invoked, which cleans up the socket (detachSocket at line 1256). So the code as currently implemented is not expecting that an error event on the socket can be received after the full response has been received.
I'm no longer seeing the issue with v0.4 HEAD either... Although I didn't have a reproducible test case to begin with, so I can't say with 100% certainty that it is fixed. It's not obvious to me from looking at the source that the recent code changes would have fixed this. Someone who is closer to the code I referenced above might want to take a look and try to deduce whether this issue could still happen with the latest code.
This issue is definitely still happening for me on v0.4 HEAD. The current stack trace follows. I wish I had a reproducible test case to provide, but the server I am connecting to is not under my control and I am not exactly sure what is causing this. My theory is still that it is due to the server occasionally not doing a proper shutdown of the SSL connection.
TypeError: Cannot call method 'emit' of undefined
at CleartextStream. (http.js:1167:9)
at CleartextStream.emit (events.js:42:17)
at Socket.onerror (tls.js:830:17)
at Socket.emit (events.js:42:17)
at Array.0 (net.js:799:27)
at EventEmitter._tickCallback (node.js:108:26)
No unfortunately not. Still not fixed for me while testing an https connection with a Python Gevent server. The server complains: "error: [Errno 104] Connection reset by peer"
I've updated to v0.4 HEAD and am still occasionally seeing this error. Stack trace follows. Once again, unfortunately I do not control the server side of the conversation, so I am not exactly sure what is happening or how to reproduce it, but it does seem that there is still an error condition out there which is not being handled.
TypeError: Cannot call method 'emit' of undefined
at CleartextStream. (http.js:1202:9)
at CleartextStream.emit (events.js:64:17)
at Socket.onerror (tls.js:888:17)
at Socket.emit (events.js:64:17)
at Array. (net.js:828:27)
at EventEmitter._tickCallback (node.js:126:26)
Stack trace: TypeError: Cannot call method 'emit' of undefined
at CleartextStream. (http.js:1202:9)
at CleartextStream.emit (events.js:64:17)
at Socket.onerror (tls.js:888:17)
at Socket.emit (events.js:64:17)
at Array. (net.js:824:27)
at EventEmitter._tickCallback (node.js:126:26)
Activity
ry commentedon Feb 15, 2011
i think you're not listening for the error event.
twills commentedon Feb 15, 2011
I believe I am. My code basically looks like the following. Should I be doing something differently?
webholics commentedon Feb 17, 2011
Same happens in my code and I'm also listening to the request error event.
ry commentedon Feb 18, 2011
please check again on v0.4 HEAD, we've made a lot of changes recently
webholics commentedon Feb 18, 2011
great seems to work in current v0.4 HEAD!
ry commentedon Feb 18, 2011
closing. reopen if it persists.
twills commentedon Feb 18, 2011
I'm no longer seeing the issue with v0.4 HEAD either... Although I didn't have a reproducible test case to begin with, so I can't say with 100% certainty that it is fixed. It's not obvious to me from looking at the source that the recent code changes would have fixed this. Someone who is closer to the code I referenced above might want to take a look and try to deduce whether this issue could still happen with the latest code.
twills commentedon Mar 16, 2011
This issue is definitely still happening for me on v0.4 HEAD. The current stack trace follows. I wish I had a reproducible test case to provide, but the server I am connecting to is not under my control and I am not exactly sure what is causing this. My theory is still that it is due to the server occasionally not doing a proper shutdown of the SSL connection.
TypeError: Cannot call method 'emit' of undefined
at CleartextStream. (http.js:1167:9)
at CleartextStream.emit (events.js:42:17)
at Socket.onerror (tls.js:830:17)
at Socket.emit (events.js:42:17)
at Array.0 (net.js:799:27)
at EventEmitter._tickCallback (node.js:108:26)
webholics commentedon Mar 17, 2011
I have still the same problem while talking with a Python Gevent SSL server.
webholics commentedon Mar 17, 2011
Addition: It works with the 0.4.2 release but not with the v4.0 head anymore.
twills commentedon Mar 17, 2011
So you are saying that you do not see the problem with node 0.4.2? If that is the case, I will try 0.4.2 and see if it is fixed for me as well.
webholics commentedon Mar 18, 2011
Yes exactly try if it works for you with 0.4.2.
ry commentedon Mar 18, 2011
need a reproducible test. also we just landed an important fix
66570c1
please try again with v0.4 HEAD or v0.4.3 which I will release today.
webholics commentedon Mar 18, 2011
No unfortunately not. Still not fixed for me while testing an https connection with a Python Gevent server. The server complains: "error: [Errno 104] Connection reset by peer"
23 remaining items
webholics commentedon Apr 14, 2011
@marsch I played again with https://gist.github.com/915603 and added your return statement before assert(0); in http.js
Now I'm able to catch the error with response.socket.on('error',..). It returns the following error:
{ stack: [Getter/Setter], arguments: undefined, type: undefined, message: 'ECONNRESET, Connection reset by peer', errno: 104, code: 'ECONNRESET', syscall: 'read' }Maybe this helps?
Don't emit error on ECONNRESET - just close
ry commentedon Apr 14, 2011
please try the above patch
webholics commentedon Apr 14, 2011
Great, seems fixed for me now, too. I can't reproduce the error anymore.
twills commentedon Apr 15, 2011
I've updated to v0.4 HEAD and am still occasionally seeing this error. Stack trace follows. Once again, unfortunately I do not control the server side of the conversation, so I am not exactly sure what is happening or how to reproduce it, but it does seem that there is still an error condition out there which is not being handled.
TypeError: Cannot call method 'emit' of undefined
at CleartextStream. (http.js:1202:9)
at CleartextStream.emit (events.js:64:17)
at Socket.onerror (tls.js:888:17)
at Socket.emit (events.js:64:17)
at Array. (net.js:828:27)
at EventEmitter._tickCallback (node.js:126:26)
satyamshekhar commentedon May 24, 2011
I get the same error on node v0.4.6
Stack trace: TypeError: Cannot call method 'emit' of undefined
at CleartextStream. (http.js:1202:9)
at CleartextStream.emit (events.js:64:17)
at Socket.onerror (tls.js:888:17)
at Socket.emit (events.js:64:17)
at Array. (net.js:824:27)
at EventEmitter._tickCallback (node.js:126:26)
sh1mmer commentedon Oct 24, 2011
Can someone try this with 0.5 HEAD? Otherwise I'd like to close it.
aseemk commentedon Nov 10, 2011
+1
bnoordhuis commentedon Feb 17, 2012
Closing, stale (and fixed). If anyone is still experiencing issues, please report them.
test: remove disabled test
test: remove disabled test
test: remove disabled test
test: remove disabled test