Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

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

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

Comments

@cakebaker
Copy link

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
Copy link

naneau commented Mar 14, 2011

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
Copy link

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
Copy link

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

@ry
Copy link

ry commented Mar 17, 2011

@stephank
Copy link

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

@ry
Copy link

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 as completed Mar 18, 2011
coolaj86 pushed a commit that referenced this issue Apr 15, 2011
Thanks to Stéphan Kochen for the fix and Maurice Fonk for reproducing the
bug.

Closes GH-784.
Closes GH-803.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants