-
Notifications
You must be signed in to change notification settings - Fork 3k
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
debounceTime + 0 + asapScheduler doesn't emit in special case #7205
Comments
I've prepared test to make a fix, finally I finished on the version with pure code without testScheduler or other helpers, here it is https://stackblitz.com/edit/typescript-gceozz?file=index.ts ('expect' part is commented and replaced with console.log). |
RxJS Team, I've created pull request (#7207) to master. I need your assistance to understand the problem with test (described above). If having test is not critical in current situation PR can be reviewed and merged. Also, I didn't find in contributing rules information about versions: should I cherry-pick changes and create PR to 7.x branch? |
@benlesh, RxJS Team, any ideas regarding problem with testing environment? Could PR related to this issue be merged without test? |
No.
This is likely nature of testscheduler only runs synchronously, so if there's inner logic involves async it may skew behaviors. Best approach is to write test without involving testsheduler if async is must to be used, or either in opposite write a test without involving async with testscheduler. |
Hi @kwonoj, thank you for your comment. Please, check my message above (and stackblitz link)
This is exactly what I did. Code in stackblitz gives wrong result, but if I put exactly the same code into spec file and run tests - result is different. That is the reason I can't put test into PR. |
It is unclear to say why stackblitz / other runtime behaves differently. That should be clarified to check in pr: all of tests / codes runs same as long as we have same runtime (node/browsers) |
only having problem in stackblitz no deadlock to other js engines |
I think I have observed a similar situation when using |
Describe the bug
In a special case when we have two (or more) subscriptions on one subject with emitting to three (or more) other subjects (all subscriptions with debounceTime(0, asapScheduler)), all emissions stop after couple of steps. Prepared example looks like not real, but it is a model of a real example we have in the application (listening to form control changes with debounceTime(0, asapScheduler) to have only one emit per task, and value change can cause synchronous calculation that will change other controls).
In given example if you keep only subscription to subject1 and subject2 - works good; subject1 and subject2 and subject3 - works with a bit wrong sequence; subject1 and subject2 and subject3 and subject4 - stuck.
Expected behavior
All subscriptions "give" values, no "deadlock" in the process.
Reproduction code
No response
Reproduction URL
https://stackblitz.com/edit/typescript-evwjuc?file=index.ts
Version
7.8.0
Environment
No response
Additional context
The reason is that 'activeTask' inside 'debounceTime' stuck forever and is not realized, all new messages are ignored because new message is scheduled only "if (!activeTask)" (line 107). I am not totally sure, but I would say process looks like this:
I would say problem is that 'local' logic of 'debounceTime' depends on 'shared' variable '_scheduled', it is not clear why. It is ok to use '_scheduler' to decide if new task id should be planned or the same (line 22, AsapAction.ts), but this variable can be changed in different places, so when 'flash' is executed it is not guaranteed value is appropriate. I guess logic is that all actions with the same id should be executed one by one, so maybe it is better to pass 'flushId' directly to 'flush' method as an argument or take 'flushId' from first 'action' in the array.
The text was updated successfully, but these errors were encountered: