-
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
Probable serious bug in .take operator (and .first and probably others?) #1993
Comments
Additionally, adding |
For me this seems same case to #1759 (comment), trying to synchronous reentrant causes it trapped can be resolved by introduce async boundaries as suggested in comment. |
@kwonoj it's the same issue. but i don't agree with that comment i'll reply there. thank you. |
Hello @trxcllnt I was pointed here thanks to my other #1993 . The current .take implementation reads in ts: protected _next(value: T): void {
const total = this.total;
const count = ++this.count;
if (count <= total) {
this.destination.next(value);
if (count === total) {
this.destination.complete();
this.unsubscribe();
}
}
} but the js code in node version 5.0.0-beta.12 gets compiled as follows: TakeSubscriber.prototype._next = function (value) {
var total = this.total;
if (++this.count <= total) {
this.destination.next(value);
if (this.count === total) {
this.destination.complete();
this.unsubscribe();
}
}
}; as you can see, feeding an item will cause this.count to be incremented before I cloned rxjs and run build_all but it looks like I can't get the wrong js code in none of the generated .js |
if you're referring this changes #1967, it's checked in but new package hasn't been published yet. |
Whoa... That's not good. Seems like a problem with the TypeScript compiler. |
Okay, so for whatever reason, what's been deployed built with this bug, but I can't get any version of TSC to build the same code to have this error locally... very strange. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hello all, I spend the whole morning trying to figure out what was wrong in my code. Hope this will help.
RxJS version: 5.0.0-beta.12
Code to reproduce:
Expected behavior:
Output:
Actual behavior:
Additional information:
Since the underlying observable
source
emits something synchronously, the latter data is discarded by the take operator butthis.destination.complete()
withintake
implementation never gets called (cause count gets incremented by thesource.next
emission and when theif(this.count === total)
gets evaluatedthis.count
does not evaluate to1
anymore but to2
.Possible Solution:
saving current count in the
_next
closure will fix the problem.Similar problem within
.first
operatorif
.take(1)
within the previous example is changed to.first()
then an Call stack limit exceeded is triggered and all the1
s are getting throughfirst
. This is almost the same problem but the fix can be done by setting a_lock
variable within the_emitFinal
fn under the .first implementation.Conclusion
While this might seem a stupid bug considering the sample. It happened to me in a situation where there was no direct correlation between the
onNext
fn and thesource
observable. Instead, in my code, I was calling a fn (not rx native) that changed the underlying data of thesource
observable causing it to re-emit the changes.The text was updated successfully, but these errors were encountered: