Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: debounceTime with asapScheduler deadlock because of nested calls #7207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yuri-apanasik
Copy link

@yuri-apanasik yuri-apanasik commented Mar 7, 2023

Description:

Related to (#7205)

BREAKING CHANGE:

Related issue (if exists):

@benlesh
Copy link
Member

benlesh commented Mar 7, 2023

Hi, @yuri-apanasik, thank you for your contribution. Please add a test and confirm that the test is broken in master prior to changing any code.

@yuri-apanasik
Copy link
Author

Hi @benlesh, as a wrote here (#7207) I have a problem with test, behavior is different in testing environment and runtime. Do you have any ideas why this difference could be?


const { actions } = this;
let error: any;
action = action || actions.shift()!;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
action = action || actions.shift()!;
action = action ?? actions.shift()!;

@pmoleri
Copy link

pmoleri commented Mar 5, 2024

Hi @yuri-apanasik
I think that the correct code should be analogous to this patch:
https://github.com/ReactiveX/rxjs/pull/7444/files#diff-64da125812f733a97ec0d18250db7664156743309052001c7a5eeaf2109a822b
With action.id taking precedence and _scheduled only cleaned when it's its case.

Hi @benlesh, as a wrote here (#7207) I have a problem with test, behavior is different in testing environment and runtime. Do you have any ideas why this difference could be?

In my PR I also noticed some asap tests that were failing until I changed the way in which fakeTimers were registered.
You could check if that fixes (or make fail) your tests too,

@yuri-apanasik
Copy link
Author

Hi @pmoleri , to tell the truth I even forgot about this PR... As I remember and as I can see in the code, global logic with both patches (your or mine) will be the same. I would say we can wait until at least one PR will be merged by maintainers and adjust another PR so code in both animationFrame/asap schedulers is consistent.
Thank you for the hint with tests. I'll try to fix them on the weekend.

@pmoleri
Copy link

pmoleri commented Mar 6, 2024

@yuri-apanasik

global logic with both patches (your or mine) will be the same

The code communicates different intents, although, in practice it might end up being equivalent because of specifics about asapScheduler.

In your code _scheduled is taking precedence as flushid and is always clearing the _scheduled, even if the dispatched action was in the parameter with a different id.
This has 2 consequences:

  • It may flush unrelated actions
  • It will clear the _scheduled when it's not its turn.

In asapScheduler, in my experience _scheduled actions always get flushed before any other delayed action, so those consequences don't have any negative impact. In animationFrameScheduler it's critical, because delayed action can indeed happen before _scheduled ones having very negative consequences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants