diff options
author | Rafael Silva <rafael.nunu@hotmail.com> | 2022-02-06 12:28:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-06 12:28:55 +0300 |
commit | 1c7a74e6f76923e3261fa17e6de98fd47bc1f8f1 (patch) | |
tree | 4bb921036b41d121c2af49f54e660a8b37331d5d /doc/api/stream.md | |
parent | 365e5f552934bc0b510b9854a6cc6c861ef5f460 (diff) |
doc: add stream pipelining note on Http usage
PR-URL: https://github.com/nodejs/node/pull/41796
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Mary Marchini <oss@mmarchini.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api/stream.md')
-rw-r--r-- | doc/api/stream.md | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/doc/api/stream.md b/doc/api/stream.md index 265e3a4ce46..ecfd4a62e64 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -2522,6 +2522,28 @@ run().catch(console.error); after the `callback` has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and swallowed errors. +`stream.pipeline()` closes all the streams when an error is raised. +The `IncomingRequest` usage with `pipeline` could lead to an unexpected behavior +once it would destroy the socket without sending the expected response. +See the example below: + +```js +const fs = require('fs'); +const http = require('http'); +const { pipeline } = require('stream'); + +const server = http.createServer((req, res) => { + const fileStream = fs.createReadStream('./fileNotExist.txt'); + pipeline(fileStream, res, (err) => { + if (err) { + console.log(err); // No such file + // this message can't be sent once `pipeline` already destroyed the socket + return res.end('error!!!'); + } + }); +}); +``` + ### `stream.compose(...streams)` <!-- YAML |