diff options
author | Mathias Buus <mathiasbuus@gmail.com> | 2018-01-29 19:32:34 +0100 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2018-03-06 13:31:56 +0100 |
commit | 5e3f51648ed5de36b01d53bde13fb6fb7b965667 (patch) | |
tree | a134fb92b8b846e195ea3f960131fcc9147533e6 /doc | |
parent | acac0f852a02c2b129adbc51e0bd8bd482d791af (diff) | |
download | node-new-5e3f51648ed5de36b01d53bde13fb6fb7b965667.tar.gz |
stream: updated streams error handling
This improves error handling for streams in a few ways.
1. It ensures that no user defined methods (_read, _write, ...) are run
after .destroy has been called.
2. It introduces an explicit error to tell the user if they are write to
write, etc to the stream after it has been destroyed.
3. It makes streams always emit close as the last thing after they have
been destroyed
4. Changes the default _destroy to not gracefully end streams.
It also updates net, http2, zlib and fs to the new error handling.
PR-URL: https://github.com/nodejs/node/pull/18438
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/errors.md | 11 | ||||
-rw-r--r-- | doc/api/stream.md | 19 |
2 files changed, 21 insertions, 9 deletions
diff --git a/doc/api/errors.md b/doc/api/errors.md index b9c52ad0d9..70ac01de61 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1449,6 +1449,12 @@ An unspecified or non-specific system error has occurred within the Node.js process. The error object will have an `err.info` object property with additional details. +<a id="ERR_STREAM_DESTROYED"></a> +### ERR_STREAM_DESTROYED + +A stream method was called that cannot complete because the stream was +destroyed using `stream.destroy()`. + <a id="ERR_TLS_CERT_ALTNAME_INVALID"></a> ### ERR_TLS_CERT_ALTNAME_INVALID @@ -1615,11 +1621,6 @@ The fulfilled value of a linking promise is not a `vm.Module` object. The current module's status does not allow for this operation. The specific meaning of the error depends on the specific function. -<a id="ERR_ZLIB_BINDING_CLOSED"></a> -### ERR_ZLIB_BINDING_CLOSED - -An attempt was made to use a `zlib` object after it has already been closed. - <a id="ERR_ZLIB_INITIALIZATION_FAILED"></a> ### ERR_ZLIB_INITIALIZATION_FAILED diff --git a/doc/api/stream.md b/doc/api/stream.md index 5db990d4d2..32e368f05f 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -543,8 +543,10 @@ added: v8.0.0 * Returns: {this} -Destroy the stream, and emit the passed error. After this call, the -writable stream has ended. Implementors should not override this method, +Destroy the stream, and emit the passed `error` and a `close` event. +After this call, the writable stream has ended and subsequent calls +to `write` / `end` will give an `ERR_STREAM_DESTROYED` error. +Implementors should not override this method, but instead implement [`writable._destroy`][writable-_destroy]. ### Readable Streams @@ -1167,8 +1169,9 @@ myReader.on('readable', () => { added: v8.0.0 --> -Destroy the stream, and emit `'error'`. After this call, the -readable stream will release any internal resources. +Destroy the stream, and emit `'error'` and `close`. After this call, the +readable stream will release any internal resources and subsequent calls +to `push` will be ignored. Implementors should not override this method, but instead implement [`readable._destroy`][readable-_destroy]. @@ -1382,6 +1385,12 @@ constructor and implement the `writable._write()` method. The `writable._writev()` method *may* also be implemented. #### Constructor: new stream.Writable([options]) +<!-- YAML +changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/18438 + description: Add `emitClose` option to specify if `close` is emitted on destroy +--> * `options` {Object} * `highWaterMark` {number} Buffer level when @@ -1395,6 +1404,8 @@ constructor and implement the `writable._write()` method. The it becomes possible to write JavaScript values other than string, `Buffer` or `Uint8Array` if supported by the stream implementation. Defaults to `false` + * `emitClose` {boolean} Whether or not the stream should emit `close` + after it has been destroyed. Defaults to `true` * `write` {Function} Implementation for the [`stream._write()`][stream-_write] method. * `writev` {Function} Implementation for the |