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

got 'finish' event before all pending jobs done #7

Closed
jacobbubu opened this issue Apr 21, 2015 · 9 comments
Closed

got 'finish' event before all pending jobs done #7

jacobbubu opened this issue Apr 21, 2015 · 9 comments

Comments

@jacobbubu
Copy link

When use it to implement a writeable stream, the 'finish' event fired before all of the pending jobs done.

@almost
Copy link
Owner

almost commented Apr 26, 2015

You're right that it should definitely wait until all transforms are complete before firing 'finish'. I'm trying to figure out a nice way of fixing this at the moment. If you had a test case showing the failure that'd be really helpful, even more so if it was in the form of a failing unit test :)

@serp-dev
Copy link

I also encountered such a problem. Here are small tests for dimontration:
serp-dev@f7b5248

@almost
Copy link
Owner

almost commented Apr 7, 2017

Thanks for this!

@YounGoat
Copy link

YounGoat commented May 3, 2017

@jacobbubu Maybe it is triggered by duplicated invoking of callback?

@duanshiqiang
Copy link

This is a really annoying bug, it swallow us a whole afternoon to figure out why some chunk are missing. Hope it can be fixed asap..

@YounGoat
Copy link

YounGoat commented Dec 25, 2017 via email

@moander
Copy link

moander commented Jun 3, 2018

I tried this because I had the same issue using alternative package parallel-transform. Is it no real alternative to do get parallel streams?

mafintosh/parallel-transform#4

@Tapppi
Copy link
Contributor

Tapppi commented Jul 19, 2018

@almost This is due to using _flush to make sure all processing is done. That is called after the Writable side has already closed (and finish called). Node 8 added _final which is _flush but for the writing side, which allows to easily wait for all processing to complete without emitting finished.

An example fix is here mafintosh/parallel-transform#6, but that depends on readable-stream@^2.3.0 as that is the version that added Node 8 support. I think the only sensible way of surely fixing this here is to include readable-stream@^2.3.0 as a dependency to force through2 to also use a newer version (should work in any of the myriad dep tree cases?). Another possibility is to set both _final and _flush to fix it for anyone using non-ancient deps and fall back to the old behaviour otherwise.

Fixing this without _final involves monkey-patching end(), at least one dude used to do this before _final, but at least I don't feel like that 😂.

Tapppi added a commit to Tapppi/through2-concurrent that referenced this issue Jul 19, 2018
Tapppi added a commit to Tapppi/through2-concurrent that referenced this issue Jul 19, 2018
Tapppi added a commit to Tapppi/through2-concurrent that referenced this issue Jul 19, 2018
Tapppi added a commit to Tapppi/through2-concurrent that referenced this issue Jul 19, 2018
Tapppi added a commit to Tapppi/through2-concurrent that referenced this issue Jul 19, 2018
@almost almost closed this as completed in 1025bc0 Aug 10, 2018
almost added a commit that referenced this issue Aug 10, 2018
Use final instead of flush when available, fixes #7
@almost
Copy link
Owner

almost commented Aug 10, 2018

Thanks to @Tapppi for fixing this! Now published to npm as version 2.0.0 (bumped the major version because this changes semantics)

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

No branches or pull requests

7 participants