GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: avoid premature close when will not emit close · nodejs/node@ac9a4ab

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/streams
    • end-of-stream.js
  • test/parallel
    • test-stream-finished.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/end-of-stream.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/end-of-stream.js
+16-4Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ function eos(stream, options, callback) {
151151
callback.call(stream);
152152
};
153153

154+
const onclosed = () => {
155+
closed = true;
156+
157+
const errored = isWritableErrored(stream) || isReadableErrored(stream);
158+
159+
if (errored && typeof errored !== 'boolean') {
160+
return callback.call(stream, errored);
161+
}
162+
163+
callback.call(stream);
164+
};
165+
154166
const onrequest = () => {
155167
stream.req.on('finish', onfinish);
156168
};
@@ -186,22 +198,22 @@ function eos(stream, options, callback) {
186198
process.nextTick(onclose);
187199
} else if (wState?.errorEmitted || rState?.errorEmitted) {
188200
if (!willEmitClose) {
189-
process.nextTick(onclose);
201+
process.nextTick(onclosed);
190202
}
191203
} else if (
192204
!readable &&
193205
(!willEmitClose || isReadable(stream)) &&
194206
(writableFinished || isWritable(stream) === false)
195207
) {
196-
process.nextTick(onclose);
208+
process.nextTick(onclosed);
197209
} else if (
198210
!writable &&
199211
(!willEmitClose || isWritable(stream)) &&
200212
(readableFinished || isReadable(stream) === false)
201213
) {
202-
process.nextTick(onclose);
214+
process.nextTick(onclosed);
203215
} else if ((rState && stream.req && stream.aborted)) {
204-
process.nextTick(onclose);
216+
process.nextTick(onclosed);
205217
}
206218

207219
const cleanup = () => {
Collapse file

‎test/parallel/test-stream-finished.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-finished.js
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,3 +667,17 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
667667
).end();
668668
});
669669
}
670+
671+
{
672+
const stream = new Duplex({
673+
write(chunk, enc, cb) {
674+
setImmediate(cb);
675+
}
676+
});
677+
678+
stream.end('foo');
679+
680+
finished(stream, { readable: false }, common.mustCall((err) => {
681+
assert(!err);
682+
}));
683+
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.