I am doing the following fairly simple request in series, for a certain amount of variables (~100) (the problem also happens for different hostnames and paths, but always when a lot of similar requests are sent to the same host)
var http = require('http');
var request = http.request({
hostname: 'lookup.dbpedia.org',
path: '/api/search/KeywordSearch?QueryString=' + [VARIABLE],
headers: {
'Accept': 'application/json'
}
});
request.on('response', function (response) {
var data = [];
response.on('data', function (chunk) {
data.push(chunk);
});
response.on('end', function () {
var object = JSON.parse(data.join(''))
});
});
request.end();
The problem is that the last chunk of the response is sometimes not caught by response.on('data')
, so the JSON.parse gives an error.
What makes it extra weird is that this only happens on my computer, and not on another (both are Windows 7).
The problem persists for node v0.12.2 and v0.12.7, and as far I could test, this is a node issue, as something like curl
always returns the entire response.
Any thoughts?