-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Series does not defend against multiple callback calls #559
Comments
Related to #535 . I don't think a consensus was reached on whether to defend against this... |
@aearly thank you for pointing to the previous discussion about this. I personally like the idea of making async strict by default. However given the reach of this library I would make the transition gradually: Step 1: The soft fix
Step 2: The hard fix
Step 3: Clean table
If you want to do less work and be a bit more cruel, you can maybe go to Step 2 straight away. However I would sadly have to personally voice my opinion against it. This is due to the NPM dependency problem outlined above and the fact that due to it, even careful developers who have bound their code to exact NPM version numbers might get sudden and very hard to debug error crashes. This is because they might have used some version of some library which is more lax with the version of async which they depend on, while still containing code that works by accident given the current state of things. I would definitely love to get also @caolan involved in this discussion. |
Actually it seems that NPM already does have a "npm shrinkwrap" feature which allows the user to bind specific versions recursively for the whole dependency tree.. Which is great! I have no idea how I have been able to miss this before, but it pretty much means that Step 2 could just be jumped over as the developers have the option to fix the async version of misbehaving dependencies after they have identified them during Step 1. |
While I'm still on the fence as to whether async should guard against improper async functions, guarding against this and throwing an error when an iterator calls-back twice would be a good candidate feature for a 1.0 release. Skip straight to Step 3. If we're going to do it, do it soon. |
This bug seems like it's already fixed (as of HEAD - 9939951). Check out this behavior with async.series: So it seems that async.series now guards against multiple calls to the same callback. async.waterfall, on the other hand, allows callbacks to be called multiple times, but will only call the final (error or done) callback once. This behavior seems inconsistent and should be documented, if intended. How would one now use the old behavior of async.series if code depended on multiple calls to the same callback? Consider this code: https://gist.github.com/smtlaissezfaire/016b54bc906a2dc7df87 |
@smtlaissezfaire I agree that this is inconsistent, although I personally would view the ability to call callbacks multiple times a bug in itself. However I think it would be best to close this issue if the original "series" problem has been fixed in a new release (I believe this has indeed happened based on discussion in other threads), and create a new issue for this so that we can discuss the changes required to fix this in isolation. Could you post a fresh bug issue about this, then post a comment here linking to that issue? Specifically I would like to see the title not containing the word "series", as it links to both the functions that have "series" in their names, and an internal series structure used within the library to implement these. The issue you describe does not relate to either of them, so it would be better to have a new, clean issue. We could then close this one and keep the issue space in a bit more manageable state :) |
The most recent version throws an error with the code attached in the first comment:
I would consider this bug fixed. |
@smtlaissezfaire The example in your gist could be changed to separate the creation and adding of the event handler from the validation and submitting steps. |
Series should defend against multiple callbacks now. |
The bug also causes last functions in the series to not be executed if preceding functions call the callback multiple times.
We could fix this by using the only_once() wrapper but I am a bit hesitant to do this as only_once actually throws an Error, which might cause some existing code to fail.
@caolan can you give your opinion on wether we should create a "silent_only_once" which would allow iterables to call the callback multiple times without throwing an Error, but would deactivate the callback after the first call, guard the actual series execution against multiple calls?
The text was updated successfully, but these errors were encountered: