Skip to content

stream: fix _final and 'prefinish' timing

This PR fixes a few different things:

The timing of 'prefinish' depends on whether or not _final is defined. In one case the event is emitted synchronously with end() and otherwise asynchronously.

_final is currently unecessarily called asynchronously which forces implementors to use 'prefinish' as a hack to emulate synchronous behaviour. Furthermore, this hack is subtly broken due to the above issue.

The stream should not finish if errored or destroyed synchronously during the prefinish stage.

Refs: https://github.com/nodejs/node/issues/31401 Refs: https://github.com/nodejs/node/pull/32763#discussion_r407041983

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Merge request reports

Loading