-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: disallow stream methods on finished stream
Invoke callback with ERR_STREAM_ALREADY_FINISHED error if `end()` is called on a finished stream. PR-URL: #28687 Refs: #28667 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Rich Trott <[email protected]>
- Loading branch information
Showing
6 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
const server = http.createServer(common.mustCall(function(req, res) { | ||
res.end('testing ended state', common.mustCall()); | ||
res.end(common.mustCall()); | ||
res.on('finish', common.mustCall(() => { | ||
res.end(common.mustCall((err) => { | ||
assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED'); | ||
server.close(); | ||
})); | ||
})); | ||
})); | ||
|
||
server.listen(0); | ||
|
||
server.on('listening', common.mustCall(function() { | ||
http | ||
.request({ | ||
port: server.address().port, | ||
method: 'GET', | ||
path: '/' | ||
}) | ||
.end(); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const assert = require('assert'); | ||
const stream = require('stream'); | ||
|
||
const writable = new stream.Writable(); | ||
|
||
writable._write = (chunk, encoding, cb) => { | ||
setTimeout(() => cb(), 10); | ||
}; | ||
|
||
writable.end('testing ended state', common.mustCall()); | ||
writable.end(common.mustCall()); | ||
writable.on('finish', common.mustCall(() => { | ||
writable.end(common.mustCall((err) => { | ||
assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED'); | ||
})); | ||
})); |