ReactiveX / ReactiveX/rxjs

Infinite loop in closed async actions

Open
#7,148 0 comments 1 reaction 0 assignees View on GitHub

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)
  • setInterval is now created to fire in delay time
  • delay time passes
  • execute is called
  • clearInterval is called (via the recycle method)

If the action is closed when we call schedule, nothing will happen as you can see here:

https://github.com/ReactiveX/rxjs/blob/630d2b009b5ae4e8f2a62d9740738c1ec317c2d5/src/internal/scheduler/AsyncAction.ts#L21-L23

However, if the action is closed while we're waiting for delay time to pass, we will hit this:

https://github.com/ReactiveX/rxjs/blob/630d2b009b5ae4e8f2a62d9740738c1ec317c2d5/src/internal/scheduler/AsyncAction.ts#L90-L92

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.