Infinite loop in closed async actions
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 31.7k
- Forks
- 3k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
AsyncAction uses setInterval for delays, likely due to the fact setTimeout is often throttled/less accurate.
So the flow seems to roughly be this:
schedule(state, delay)setIntervalis now created to fire indelaytimedelaytime passesexecuteis calledclearIntervalis called (via the recycle method)
If the action is closed when we call schedule, nothing will happen as you can see here:
However, if the action is closed while we're waiting for delay time to pass, we will hit this:
This means we throw and never clear the interval.
The interval then continues to fire forever (since it is an interval after all, being used as if it were a timeout), throwing the same Error infinitely.
This shouldn't be possible anyway because closing the subscription should be done via unsubscribe, which will clear the interval. There's probably a separate bug or a problem on my end that results in this weird state happening. However, its probably still sensible to cover the inf loop purely from a logic point of view even if you think it shouldn't ever be hit.
Expected behavior
A few less infinite loops
Reproduction code
No response
Reproduction URL
No response
Version
latest (exists in 7 & 8)
Environment
No response
Additional context
No response
Contributor guide
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.
Research direction
Start at src/internal/scheduler/AsyncAction.ts, especially the schedule and recycle paths linked in the report. Trace the closed-action path while its delay interval is active, then verify that the interval is cleared and the error is not emitted repeatedly using the scheduler's tests or a minimal reproduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100