`err` event not triggered on endless redirects (node16 specific)
julianlam opened this issue · comments
Hi there,
If a URL is passed in that sends back a redirect to an url that sends back a redirect, repeat ad nauseam... needle doesn't throw an error anymore, at least on Node v16.14.0
The affected URL is http://www.sri-lanka-live.de/Fauna_Flora/Schmetterlinge_1/Falter_2_4.jpg
, which is a misconfigured web server that endlessly redirects requests by prepending index.php/
to the path. Warning: This is not my web server, nor do I have control over it – you can likely reproduce this by misconfiguring a proxy server to redirect something from http to https and back again.
Anyhow, on Node 14, it throws (or triggers) this error:
Error: Remote end closed socket abruptly.
at TLSSocket.on_socket_end (/path/to/needle/lib/needle.js:529:17)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
Now it hangs forever.
I have some sample code that seems to trigger this behaviour:
const needle = require('needle');
const badUrl = 'http://www.sri-lanka-live.de/Fauna_Flora/Schmetterlinge_1/Falter_2_4.jpg';
const stream = needle.get(badUrl, { follow_max: 2 });
stream.on('redirect', (location) => {
console.log(`redirected to ${location}`);
});
stream.on('err', (e) => {
console.log(error);
});
stream.on('data', (data) => {
console.log('received', data);
});
process.stdin.resume();
It seems follow_max
is adhered to, but instead of throwing the aforementioned error, nothing happens at all.
@xiaoyang678 @julianlam Feel free to submit a PR to address this issue :)
@xiaoyang678 @julianlam Feel free to submit a PR to address this issue :)
i think v3.2.0 is fixed this issue, #413 , please close.