-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
zlib.*Sync methods fire asynchorous callbacks #1668
Comments
@Qard It's not the garbage collector that is broken as you supposed in #1665 (comment), it's |
I didn't say garbage collection was broken, I said your expectations of it were incorrect and that there needed to be documentation to explain that. In this case, the objects are not collectable simply because they are still accessible by future code--the close emitting function. That can be fixed. JavaScript in general is not a good language for sync looping though, as you need to trigger GC manually and hope that enough things are collectable to not rapidly run out of memory. |
@ChALkeR Can you give me a code example where that manifests itself as a problem? |
@trevnorris I initially posted that to the issue: #1665 (comment) has the code sample, #1479 is the original report.
|
@ChALkeR Thanks. IMO it's a bug. |
Is that the case for |
Yes. Events always need to be asynchronous. The problem in a nutshell: // example 1
function next() {
var t = task();
t.on('complete', next);
}
// example 2
function next() {
task(next);
} In the first example, if In the second example, if the callback is synchronous, you get infinite recursion. |
@bnoordhuis But those events are not public in |
@bnoordhuis just curious, is there ever a time where a synchronous task allows adding event listeners? |
It happens in other places too (e.g. |
@piscisaureus Sorry, I should have clarified the question. Is there ever a time where the public API allows attaching events to a synchronous task? |
I'm not aware of any such APIs. |
@bnoordhuis Thanks. Just wanted to confirm that the reason this can't be done is because of our own internal way of handling these events. So, it seems at some point this should be fixed. Not volunteering for it, and it would probably help to have a discussion about it before anyone actually got started. |
WIP, probably less desirable than the other proposed fix, which also might be undesirable, but letting people comment just in case. Still needs a test. Refs: nodejs#1668
For the specific problem demonstrated with @ChALkeR's test code:
This appears to be fixed by just getting rid of the mechanism to emit Another option is to add an |
I believe #5707 is a fix for this. PTAL |
WIP right now, still need to do it for more methods than just gunzipSync(). Refs: nodejs#1668
https://github.com/iojs/io.js/blob/v2.0.1/lib/zlib.js#L458 — this line is called even for
*Sync
methods. That's not the only one.See #1479 and #1665 (comment)
The text was updated successfully, but these errors were encountered: