TypeError: Cannot call method 'emit' of undefined when using http.get() #784

Closed
cakebaker opened this Issue Mar 13, 2011 · 6 comments

5 participants

@cakebaker

I have the following code:

var http = require('http');

var options = { host: 'www.cnbc.com',
                port: 80,
                path: '/id/41863659/',
                headers: { 'User-Agent': 'Mozilla/5.0 (Linux x86_64)' } };

http.get(options, function (res) {
    console.log('success');
}).on('error', function (e) {
    console.log('error');
});

When I run this script, I get the following error after the output of "success":

node.js:116
    throw e; // process.nextTick error, or 'error' event on first tick
    ^
TypeError: Cannot call method 'emit' of undefined
    at Socket.<anonymous> (http.js:1174:9)
    at Socket.emit (events.js:42:17)
    at Array.<anonymous> (net.js:799:27)
    at EventEmitter._tickCallback (node.js:108:26)

I don't know what's going wrong, as the script works fine with other URLs...

I'm using node.js 0.4.2.

@naneau

I'm experiencing the same issue. It seems to happen when I fire two requests in quick succession.

Offending code (in 0.4.2) at https://github.com/joyent/node/blob/v0.4.2/lib/http.js#L1174 , where req remains null.

@davinlior

I too am experiencing this issue with my local webserver when using

{host:'127.0.0.1', ... }

Of course when I browse to 127.0.0.1 in my web browser everything looks fine.

N.B. While node crashes in trying to connect to the localhost webserver, the webserver logs the connection.

Also using 0.4.2

@davinlior

I'm pretty sure I found the reason for this: node doesn't handle the absence of a Content-Length header well on normal/default Transfer-Encoding.

I explained it here:
http://stackoverflow.com/questions/5286968/node-js-process-nexttick-error/5328515#5328515

@stephank

Here's a patch which solved the problem for us: #803

@ry
ry commented Mar 18, 2011

Fix double free of parser on error in http.Agent.

Thanks to Stéphan Kochen for the fix and Maurice Fonk for reproducing the
bug.

Closed by 66570c1.
Closed by 66570c1.

@ry ry closed this Mar 18, 2011
@coolaj86 coolaj86 pushed a commit that referenced this issue Apr 15, 2011
@ry ry Fix double free of parser on error in http.Agent.
Thanks to Stéphan Kochen for the fix and Maurice Fonk for reproducing the
bug.

Closes GH-784.
Closes GH-803.
66570c1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment