Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
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

Closed
@twills

Description

@twills

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions