timeout isn't working
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- nodejs, typescript
Research direction
Start at the xhr entry point in request-light and trace how the timeout option is applied to the Node.js request. Compare its behavior with the working https example in the issue; done means a request with timeout: 1000 rejects or aborts instead of waiting for the full response.
Written by the indexing model from the issue text.
Description
AFAIK calling request.setTimeout(ms) does not automatically abort or fail the request when the timeout is reached. Instead, it simply emits a 'timeout' event on the request object where we would need to abort the request manually.
There isn't any logic in node-request-light capturing the timeout event so it will never timeout..
Recreation script (where 'request-light' is present in the node_modules folder):
const { xhr } = require('request-light');
async function testTimeout() {
const timeoutMs = 1000;
// This URL will wait for 10 seconds before responding
const url = 'https://httpbin.org/delay/10';
console.log(`Starting request to ${url} with a ${timeoutMs}ms timeout...`);
const start = Date.now();
try {
const response = await xhr({
url,
timeout: timeoutMs
});
console.log(`Request finished successfully after ${Date.now() - start}ms (Status: ${response.status})`);
} catch (error) {
const duration = Date.now() - start;
console.log(`Request failed after ${duration}ms`);
if (error.status === 408 || error.message?.includes('timeout') || duration < 2000) {
console.log('SUCCESS: The timeout was respected.');
} else {
console.log('FAILURE: The timeout was NOT respected. It likely waited for the full response.');
}
console.log('Error details:', error);
}
}
testTimeout();
working nodejs example
const https = require('https');
function testWorkingTimeout() {
const timeoutMs = 1000;
const url = 'https://httpbin.org/delay/10';
console.log(`Starting Node.js native request to ${url} with a ${timeoutMs}ms timeout...`);
const start = Date.now();
const req = https.get(url, (res) => {
console.log('This should not be reached if timeout works.');
});
// Set the timeout
req.setTimeout(timeoutMs);
// Listen for the 'timeout' event (This is what request-light is missing)
req.on('timeout', () => {
console.log(`[TIMEOUT EVENT] Triggered after ${Date.now() - start}ms. Manually destroying the request...`);
req.destroy(new Error('ETIMEDOUT'));
});
req.on('error', (err) => {
console.log(`[ERROR EVENT] Request failed as expected: ${err.message}`);
console.log(`Total duration: ${Date.now() - start}ms`);
if (Date.now() - start < 2000) {
console.log('SUCCESS: The timeout was respected because we handled the event.');
}
});
}
testWorkingTimeout();
- Dominant language
- TypeScript
- Stars
- 35
- Forks
- 22
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 2
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/node-request-light
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
microsoft/node-request-light#27 · 1 comment ·
-
NO_PROXY support Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
microsoft/node-request-light#10 · 1 reaction ·
All issues in microsoft/node-request-light
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug v2
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
modelcontextprotocol/inspector#2458 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
railmapgen/rmp-gallery#4068 ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
carbon-design-system/ibm-products#9907 ·