parseError with certain requests #109

Closed
jamespeerless opened this Issue Nov 23, 2011 · 5 comments

2 participants

@jamespeerless

Haven't had time to really dig in and figure out what's really going on here but I noticed when making certain HEAD requests the httpClient will emit a parseError and there doesn't seem to be anything you can do to stop it from crashing the thread.

Could be a node bug? It's 0.6.2. It's also possible I have no idea what I'm doing and the problem is me. Changing it to a GET request fixes the issue though.

Here's a small sample program to recreate the issue:

var request = require('request');

var options = {
url: 'http://www.aa.com/content/images/footer/footer_email.gif',
method: 'HEAD',
headers: {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Connection': 'keep-alive',
'Accept-Language': 'en-us,en;q=0.5',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20110814 Firefox/6.0'
},
followRedirect: true,
maxRedirects: 10,
jar: false,
timeout: 10000,
encoding: 'utf8',
strictSSL: false,
};

request(options,function(error,response,body){
if(error){
console.log("and we're dead");
}
});

@jamespeerless

Just noting I saw it again even after switching to GET requests. I dont get why the thread crashes when the req object emits an error. The request object handles it with clientErrorHandler by emitting it's own error and this is handled by the user defined callback. In my callback I handle the error my own.. is there something I need to do (or CAN do) to suppress this error completely?

@jamespeerless

related to this:

nodejs/node-v0.x-archive#1956

Could be a node bug, but could be something to do with multiple requests made using "request" module.

@jamespeerless

Ok figured it out, well at least fixed my issue but I think it's an actual bug in request. What appears to be happening is a race between the error handler for ClientRequest (self.req) getting setup and the request emitting an error. If the request errors before the handler is setup it will crash the thread. My workaround fix is to do this:

var r = request(options,callback);
r.on('error',handleError);

I could be totally wrong as I am total node noob, just started playing with this stuff last couple days, sorry if im wrong!

@jamespeerless

My original code still fails, maybe because HEAD request is even faster to respond than the GET requests? I'm really not sure anymore, ill wait for input from someone smarter :-/

@mikeal
request member

i was on vacation when this was logged and just got to it, is this still an issue? if it is, i'll reopen.

@mikeal mikeal closed this Feb 18, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment