| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f952605 commit 60c71dc
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,44 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + | ||
| 4 | + // Tests for the regression in _stream_writable discussed in | ||
| 5 | + // https://github.com/nodejs/node/pull/31756 | ||
| 6 | + | ||
| 7 | + // Specifically, when a write callback is invoked synchronously | ||
| 8 | + // with an error, and autoDestroy is not being used, the error | ||
| 9 | + // should still be emitted on nextTick. | ||
| 10 | + | ||
| 11 | + const { Writable } = require('stream'); | ||
| 12 | + | ||
| 13 | + class MyStream extends Writable { | ||
| 14 | + #cb = undefined; | ||
| 15 | + | ||
| 16 | + constructor() { | ||
| 17 | + super({ autoDestroy: false }); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + _write(_, __, cb) { | ||
| 21 | + this.#cb = cb; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + close() { | ||
| 25 | + // Synchronously invoke the callback with an error. | ||
| 26 | + this.#cb(new Error('foo')); | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + const stream = new MyStream(); | ||
| 31 | + | ||
| 32 | + const mustError = common.mustCall(2); | ||
| 33 | + | ||
| 34 | + stream.write('test', () => {}); | ||
| 35 | + | ||
| 36 | + // Both error callbacks should be invoked. | ||
| 37 | + | ||
| 38 | + stream.on('error', mustError); | ||
| 39 | + | ||
| 40 | + stream.close(); | ||
| 41 | + | ||
| 42 | + // Without the fix in #31756, the error handler | ||
| 43 | + // added after the call to close will not be invoked. | ||
| 44 | + stream.on('error', mustError); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments