Describe the bug
Node.js version: 18.20.4
OS version: MacOs Sequoia 15.2
Description: After causing the request to crash by supplying undefined headers, the request is not properly closed and this causes a dangling handle that lasts for a few seconds.
Actual behavior
Expected behavior
The request should be ended, even if there are unexpected exceptions.
Code to reproduce
const superagent = require('superagent');
const r = superagent.get('https://www.google.com');
try {
r.set({ 'x-header': undefined }).end((err, result) => console.log('completed', err, result));
// r.set({ 'x-header': undefined }).then(result => console.log('completed', result)).catch(err => {
console.error('rejected', err);
// r.req.end();
});
} catch(e) {
console.log('caught', e);
// r.req.end();
}
This code snippet is a setup for two scenarios:
- The current setup will use the
end() syntax and when the error is caught, the application will hang for a few seconds and then exit.
- If you uncomment the
r.req.end() line inside the catch, the application will exit immediately.
- If we comment out the first line inside the
try block and uncomment the second line, we now are testing the promise based method. This also hangs before allowing the application to exit.
- If we comment out the
r.req.end() line inside the .catch() handler, then the application exits immediately.
Checklist
Describe the bug
Node.js version: 18.20.4
OS version: MacOs Sequoia 15.2
Description: After causing the request to crash by supplying undefined headers, the request is not properly closed and this causes a dangling handle that lasts for a few seconds.
Actual behavior
Expected behavior
The request should be ended, even if there are unexpected exceptions.
Code to reproduce
This code snippet is a setup for two scenarios:
end()syntax and when the error is caught, the application will hang for a few seconds and then exit.r.req.end()line inside the catch, the application will exit immediately.tryblock and uncomment the second line, we now are testing thepromisebased method. This also hangs before allowing the application to exit.r.req.end()line inside the.catch()handler, then the application exits immediately.Checklist