| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 313ecaa commit 8a2b62e
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,27 +38,20 @@ function destroyStream(stream, err) { | |||
| 38 | 38 | ||
| 39 | 39 | function destroyer(stream, reading, writing, callback) { | |
| 40 | 40 | callback = once(callback); | |
| 41 | - | ||
| 42 | - let closed = false; | ||
| 43 | - stream.on('close', () => { | ||
| 44 | - closed = true; | ||
| 45 | - }); | ||
| 41 | + let destroyed = false; | ||
| 46 | 42 | ||
| 47 | 43 | if (eos === undefined) eos = require('internal/streams/end-of-stream'); | |
| 48 | 44 | eos(stream, { readable: reading, writable: writing }, (err) => { | |
| 49 | - if (err) return callback(err); | ||
| 50 | - closed = true; | ||
| 51 | - callback(); | ||
| 45 | + if (destroyed) return; | ||
| 46 | + destroyed = true; | ||
| 47 | + destroyStream(stream, err); | ||
| 48 | + callback(err); | ||
| 52 | 49 | }); | |
| 53 | 50 | ||
| 54 | - let destroyed = false; | ||
| 55 | 51 | return (err) => { | |
| 56 | - if (closed) return; | ||
| 57 | 52 | if (destroyed) return; | |
| 58 | 53 | destroyed = true; | |
| 59 | - | ||
| 60 | 54 | destroyStream(stream, err); | |
| 61 | - | ||
| 62 | 55 | callback(err || new ERR_STREAM_DESTROYED('pipe')); | |
| 63 | 56 | }; | |
| 64 | 57 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -763,7 +763,10 @@ const { promisify } = require('util'); | |||
| 763 | 763 | s.emit('data', 'asd'); | |
| 764 | 764 | s.emit('end'); | |
| 765 | 765 | }); | |
| 766 | - s.close = common.mustCall(); | ||
| 766 | + // 'destroyer' can be called multiple times, | ||
| 767 | + // once from stream wrapper and | ||
| 768 | + // once from iterator wrapper. | ||
| 769 | + s.close = common.mustCallAtLeast(1); | ||
| 767 | 770 | let ret = ''; | |
| 768 | 771 | pipeline(s, async function(source) { | |
| 769 | 772 | for await (const chunk of source) { | |
@@ -909,3 +912,13 @@ const { promisify } = require('util'); | |||
| 909 | 912 | assert.strictEqual(err.message, 'kaboom'); | |
| 910 | 913 | })); | |
| 911 | 914 | } | |
| 915 | + | ||
| 916 | + { | ||
| 917 | + const src = new PassThrough({ autoDestroy: false }); | ||
| 918 | + const dst = new PassThrough({ autoDestroy: false }); | ||
| 919 | + pipeline(src, dst, common.mustCall(() => { | ||
| 920 | + assert.strictEqual(src.destroyed, true); | ||
| 921 | + assert.strictEqual(dst.destroyed, true); | ||
| 922 | + })); | ||
| 923 | + src.end(); | ||
| 924 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments