Connections cleanup after timeout
- Dominant language
- TypeScript
- Stars
- 336
- Forks
- 15
- PR merge metrics
- No merged PRs in 30d
Description
Just tested the behavior of timeout and memory after running below function 100 times cycled.
Url has 3 minutes delay in response and timeout happens immideately. I thought that appropriate connection will be closed after promise is rejected with TimeoutError and everything will be cleaned. But memory grows. I tried disconnectAll after catching timeout and there is slightly better memory usage after cycle in case of that. All connections stay alive until 3 minutes passed. If we do nearly the same but using AbortController signal cancelling fetches, memory stays constant and there is no any leaks and pending connections.
So the main question is how to clean up connection immideately after timeout?
Under heavy load and under certain conditions, a memory leak will occur.
Experimented to abort after timeouts but no result.
```
async function fetchTest() {
try {
let newCtx = context();
var response = await newCtx.fetch('https://httpstat.us/200?sleep=180000',{timeout: 10});
}
catch (e) {
console.log(e.constructor.name);
newCtx.disconnectAll(); //consumes less memory with disconnecting after timeot
return {error: e.constructor.name};
}
return { body: await response.text() };
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the timeout case in fetchTest with the 180-second URL and repeated calls, comparing timeout rejection with AbortController cancellation. Inspect the paths reached by context(), fetch(), TimeoutError, and disconnectAll(). Done means timed-out connections are cleaned up immediately and repeated cycles do not retain pending connections or steadily increase memory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100