Skip to content

finished(stream, cb) invokes callback too early #32032

@ronag

Description

@ronag

The semantics of finished is to invoke the callback on 'end' and 'finish'. The problem with this is that this does not mean that the stream is actually "finished", i.e. it might still emit 'error' and has probably not yet freed all resources since 'close' is not yet emitted.

The reason we invoke it early in this way is because not all stream actually emit 'close'. I'm a little unsure how to resolve this and whether this is worth resolving.

One way could be to use setImmediate or setTimeout before invoking the callback in 'end'/'finish' in order to give a chance for 'error' or 'close' to be emitted. However, that is very much imperfect.

We might want to at least clarify this in the docs.

Thoughts? @nodejs/streams

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions