Skip to content

Commit

Permalink
doc: add stream pipelining note on Http usage
Browse files Browse the repository at this point in the history
PR-URL: #41796
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Mary Marchini <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
RafaelGSS authored and ruyadorno committed Feb 8, 2022
1 parent bd5d158 commit 5085813
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions doc/api/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -2463,6 +2463,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
Expand Down

0 comments on commit 5085813

Please sign in to comment.