-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
'open'
can be emitted after 'close'
#23133
Comments
What’s the expected behaviour? To never emit |
Probably to emit |
cc @nodejs/streams |
I guess ‘ready’ is similar to ‘open’ |
Here is an example of where this easily causes a bug. I would like to assume that this is in some form a quite common pattern. const rec = db.getRecord(blockId)
pipeline(
req,
fs.createWriteStream(blockPath, { flags: 'wx' })
.on('open', () => {
// Oops, this can be called after rec.destroy() :/.
rec.set({
path: blockPath
})
}),
err => {
rec.destroy()
callback(err)
}
) |
@ronag is this limited to files? The current mechanism is not really checking anything like that as What do you think? Would you like to assemble a PR? |
@mcollina I just noticed there is something called I'll look into doing a PR for files & |
@mcollina I still feel there are some things unclear here. What exactly is the expected behaviour in regards to streams. The stream api seems to have a i.e. if I call What exactly is the expected state of a stream after calling |
We also have |
I think the semantics for One issue here is that this event always comes from the underlying implementation, not the streams layer itself. So, it may not be easy for the streams implementation to tell whether to respect that event or not? |
There is no ‘ready’ or ‘open’ event in Streams. Objects that inherits from In theory, after calling .destroy(), no new event should be emitted. There is a known problem regarding error events, but this is not the case. The problem for fs is that we have scheduled opening a file, and when that happens the file is emitted. destroy happens in the meanwhile, because this is operation is not cancellable. I think we |
In theory, we wouldn't want |
Can you make an example @addaleax? |
@ronang that should be emitted by the .destroy cycle. |
@mcollina Sure – but example for what? If you say streams shouldn’t emit these, should we maybe just guard the |
The typical pattern for streams is inheritance, and I fear that protecting emit would likely cause some significant breakage. |
@mcollina I don’t understand… I’m not talking about changing |
Oh yes. We are in agreement then. |
@mcollina can we label this as bug? |
@ronag definitely. |
Refs: #23133 PR-URL: #29656 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Denys Otrishko <[email protected]>
This was fixed in 54b36e4 |
'open'
can be emitted after'close'
for file streams which can cause some unexpected behaviours.EDIT: Updated to after
'close'
instead of afterdestroy()
.The text was updated successfully, but these errors were encountered: