Skip to content
This repository

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

Closed
cakebaker opened this Issue · 6 comments

5 participants

Daniel Hofstetter Maurice Fonk davinlior ry Stéphan Kochen
Daniel Hofstetter

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.

Maurice Fonk

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

Stéphan Kochen

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

ry
ry commented

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
AJ ONeal coolaj86 referenced this issue from a commit
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
Something went wrong with that request. Please try again.