rxjs icon indicating copy to clipboard operation
rxjs copied to clipboard

Infinite loop in closed async actions

Open 43081j opened this issue 1 year ago • 0 comments

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

43081j avatar Jan 13 '23 09:01 43081j