Describe the bug
The timeout in the requests is being ignored because there's no listener for the timeout event.
The problem is here. The code is listening for error, but when a request times out, it emits a timeout event, that it's being ignored, so until the server fails to respond, the request will continue.
I copied the httpRequest into an isolated scenario and tried adding the following things and it seems to work:
+ let finished = false;
const req = http.request(allOptions, resp => {
let body = '';
resp.on('data', chunk => {
body += chunk;
});
resp.on('end', () => {
+ if (finished) {
+ return;
+ }
callback(null, resp, body);
});
});
req.on('error', err => {
callback(err);
});
+ req.on('timeout', () => {
+ finished = true;
+ callback(new Error('timeout'));
+ req.end();
+ });
Yeah, it could probably use a better exception :P
To reproduce
Set the timeout to a very low value and throttle your network connection.
Expected behavior
The timeout event will be handled, the connection terminated, and the promise rejected.
SDK version
Latest
Language version, developer tools
Node 16 and 18
OS/platform
MacOS 12