I have stepped on a situation in which a client can hang forever.
my HTTP client, is susceptible to getting blocked-forever, if the 3rd party server has buggy code, such as one written below.
require('http').createServer(
function (req, rsp)
{
console.log("rcvd request from client");
rsp.writeHead(200, {"Content-Type": "text/plain"});
rsp.write("Hello World 1"); /* server to send a data chunk */
// rsp.end("Hello World 2\n"); /* server not to 'end' the response */
}
).listen(24680);
the fix is trivial, in the Requestify.js
...
httpRequest = http.request(options, function(res) {
// clearTimeout(timeout); // Fix-1: move this to Fix-2, while handling 'end' event.
var response = new Response(res.statusCode, res.headers);
res.setEncoding(responseEncoding);
res.on('data', function(chunk) {
response.setChunk(chunk);
});
res.on('end', function() {
clearTimeout(timeout); // Fix-2: this is when the timer should be cleared
if (isSuccessful(response.code)) {
storeCache(request.getFullUrl(), response.getCode(), response.getHeaders(), response.body, request.cache);
defer.resolve(response);
return;
}
defer.reject(response);
});
});
...
I have stepped on a situation in which a client can hang forever.
my HTTP client, is susceptible to getting blocked-forever, if the 3rd party server has buggy code, such as one written below.
the fix is trivial, in the Requestify.js