Commit Graph

24 Commits

Author SHA1 Message Date
Robert Nagy
a55b77d2d3 stream: finished on closed OutgoingMessage
finished should invoke callback on closed OutgoingMessage the
same way as for regular streams.

Fixes: https://github.com/nodejs/node/issues/34301

PR-URL: https://github.com/nodejs/node/pull/34313
Fixes: https://github.com/nodejs/node/issues/34274
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2020-07-16 08:37:01 +02:00
rickyes
48404a179f
stream: rename opts to options
PR-URL: https://github.com/nodejs/node/pull/34339
Refs: https://nodejs.org/dist/latest-v14.x/docs/api/stream.html#stream_stream_finished_stream_options_callback
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-07-16 00:28:13 +02:00
Robert Nagy
d84f131291 stream: fix stream.finished on Duplex
finished would incorrectly believe that a Duplex is already
closed if either the readable or writable side has completed.

Fixes: https://github.com/nodejs/node/issues/33130

PR-URL: https://github.com/nodejs/node/pull/33133
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2020-04-30 14:21:49 +02:00
Robert Nagy
c15a27cab3 stream: don't wait for close on legacy streams
Try to detect non standard streams and don't wait for
'close' on these. In particular if we detected
that destroyed is true before we expect it to be then
fallback to compat behavior.

Fixes: https://github.com/nodejs/node/issues/33050

PR-URL: https://github.com/nodejs/node/pull/33058
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
2020-04-27 17:08:26 +02:00
Robert Nagy
4eb1701edb stream: finished should complete with read-only Duplex
If passed a Duplex where readable or writable has been
explicitly disabled then don't assume 'close' will be
emitted.

Fixes: https://github.com/nodejs/node/issues/32965

PR-URL: https://github.com/nodejs/node/pull/32967
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Mathias Buus <mathiasbuus@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
2020-04-23 19:47:11 +02:00
Robert Nagy
1428a92492
stream: make pipeline try to wait for 'close'
Pipeline uses eos which will invoke the callback
on 'finish' and 'end' before all streams have been
fully destroyed.

Fixes: https://github.com/nodejs/node/issues/32032

PR-URL: https://github.com/nodejs/node/pull/32158
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-03-27 15:55:21 +01:00
Robert Nagy
8429295c5b stream: eos make const state const
writable & readable is based on type and is not actual
state, treat them as such.

PR-URL: https://github.com/nodejs/node/pull/32031
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2020-03-03 19:23:01 +01:00
Robert Nagy
7cafd5f3a9 stream: fix finished w/ 'close' before 'end'
Emitting 'close' before 'end' on a Readable should
result in a premature close error.

PR-URL: https://github.com/nodejs/node/pull/31545
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-03-03 13:34:24 +01:00
Robert Nagy
21bd6679ce stream: fix finished typo
https://github.com/nodejs/node/pull/31509 introduced a slight typo.
Fortunately this typo does not have big impact due to
`isWritableFinished()`.

Fixes: https://github.com/nodejs/node/pull/31509#discussion_r381809355

PR-URL: https://github.com/nodejs/node/pull/31881
Fixes: https://github.com/nodejs/node/issues/31509
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2020-02-22 10:39:18 +01:00
Robert Nagy
d016b9d708 stream: finished callback for closed streams
Previously finished(stream, cb) would not invoke the callback
for streams that have already finished, ended or errored
before being passed to finished(stream, cb).

PR-URL: https://github.com/nodejs/node/pull/31509
Refs: https://github.com/nodejs/node/pull/31508
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-02-08 23:34:40 +01:00
Robert Nagy
234de6f1fd
stream: fix finished w/ 'close' before 'finish'
Emitting 'close' before 'finish' on a Writable should
result in a premature close error.

PR-URL: https://github.com/nodejs/node/pull/31534
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-02-05 15:48:54 +01:00
Robert Nagy
b851d7b986 stream: fix finished writable/readable state
writable/readable does not indicate whether as stream is
a Writable/Readable. This implements a better check for
whether a object is a Writable/Readable.

PR-URL: https://github.com/nodejs/node/pull/31527
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-01-28 19:49:57 -08:00
daern91
411c1a679d stream: replace var with let
PR-URL: https://github.com/nodejs/node/pull/30379
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-11-18 12:56:51 +05:30
Matteo Collina
9f873b3a65 Revert "stream: make finished call the callback if the stream is closed"
This reverts commit b03845b937.

PR-URL: https://github.com/nodejs/node/pull/29717
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
2019-10-10 10:34:12 +02:00
Matteo Collina
8c60685105 Revert "stream: remove ambiguous code"
This reverts commit ce62e963a1.

PR-URL: https://github.com/nodejs/node/pull/29717
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
2019-10-10 10:34:10 +02:00
Robert Nagy
ce62e963a1 stream: remove ambiguous code
PR-URL: https://github.com/nodejs/node/pull/29664
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2019-09-29 18:42:55 +09:00
Robert Nagy
8709a408d2 stream: use more accurate end-of-stream writable and readable detection
The value of stream.readable and stream.writable should not
be used to detect whether a stream is Writable or Readable.

Refs: https://github.com/nodejs/node/issues/29395
PR-URL: https://github.com/nodejs/node/pull/29409
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-09-22 15:47:40 -07:00
Robert Nagy
b03845b937 stream: make finished call the callback if the stream is closed
Make stream.finished callback invoked if stream is already
closed/destroyed.

PR-URL: https://github.com/nodejs/node/pull/28748
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-09-03 10:28:48 +02:00
Robert Nagy
897587c013 stream: don't deadlock on aborted stream
Not all streams (e.g. http.ClientRequest) will always emit
'close' after 'aborted'.

PR-URL: https://github.com/nodejs/node/pull/29376
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2019-09-02 16:31:33 +02:00
Robert Nagy
317fa3a757 stream: add readableEnded
Adds a readableEnded property and improved finished compat with possible
stream-like objects.

PR-URL: https://github.com/nodejs/node/pull/28814
Refs: https://github.com/nodejs/node/issues/28813
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-08-19 22:03:07 -07:00
Anna Henningsen
c9a7088bd8 stream: re-use existing once() implementation
PR-URL: https://github.com/nodejs/node/pull/24991
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2018-12-15 06:43:38 -08:00
Anna Henningsen
83ec33b933 stream: fix end-of-stream for HTTP/2
HTTP/2 streams call `.end()` on themselves from their
`.destroy()` method, which might be queued (e.g. due to network
congestion) and not processed before the stream itself is destroyed.

In that case, the `_writableState.ended` property could be set before
the stream emits its `'close'` event, and never actually emits the
`'finished'` event, confusing the end-of-stream implementation so
that it wouldn’t call its callback.

This can be fixed by watching for the end events themselves using the
existing `'finish'` and `'end'` listeners rather than relying on the
`.ended` properties of the `_...State` objects.

These properties still need to be checked to know whether stream
closure was premature – My understanding is that ideally, streams
should not emit `'close'` before `'end'` and/or `'finished'`, so this
might be another bug, but changing this would require modifying tests
and almost certainly be a breaking change.

Fixes: https://github.com/nodejs/node/issues/24456

PR-URL: https://github.com/nodejs/node/pull/24926
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2018-12-11 14:21:52 -08:00
Ruben Bridgewater
36468ca928
lib: require a callback for end-of-stream
Make the callback mandatory as mostly done in all other Node.js
callback APIs so users explicitly have to decide what to do in error
cases.

This also documents the options for `Stream.finished()`.

When originally implemented it was missed that Stream.finished() has
an optional options object.

PR-URL: https://github.com/nodejs/node/pull/21058
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Mathias Buus <mathiasbuus@gmail.com>
2018-08-22 01:00:27 +02:00
Mathias Buus
f64bebf205 stream: add pipeline and finished
PR-URL: https://github.com/nodejs/node/pull/19828
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-04-16 16:02:12 +02:00