-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
stream: call _final synchronously #30597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const Transform = require('stream').Transform; | ||
|
|
||
| const bench = common.createBenchmark(main, { | ||
| n: [2e6], | ||
| sync: ['yes', 'no'], | ||
| callback: ['yes', 'no'] | ||
| }); | ||
|
|
||
| function main({ n, sync, callback }) { | ||
| const b = Buffer.allocUnsafe(1024); | ||
| const s = new Transform(); | ||
| sync = sync === 'yes'; | ||
|
|
||
| const writecb = (cb) => { | ||
| if (sync) | ||
| cb(); | ||
| else | ||
| process.nextTick(cb); | ||
| }; | ||
|
|
||
| s._transform = (chunk, encoding, cb) => writecb(cb); | ||
|
|
||
| const cb = callback === 'yes' ? () => {} : null; | ||
|
|
||
| bench.start(); | ||
|
|
||
| let k = 0; | ||
| function run() { | ||
| while (k++ < n && s.write(b, cb)); | ||
| if (k >= n) | ||
| bench.end(n); | ||
| } | ||
| s.on('drain', run); | ||
| s.on('data', () => {}); | ||
| run(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2004,16 +2004,21 @@ class Http2Stream extends Duplex { | |
| _final(cb) { | ||
| const handle = this[kHandle]; | ||
| if (this.pending) { | ||
| this.once('ready', () => this._final(cb)); | ||
| this.once('ready', function() { | ||
| process.nextTick(() => this._final(cb)); | ||
| }); | ||
| } else if (handle !== undefined) { | ||
| debugStreamObj(this, '_final shutting down'); | ||
| const req = new ShutdownWrap(); | ||
| req.oncomplete = afterShutdown; | ||
| req.callback = cb; | ||
| req.handle = handle; | ||
| const err = handle.shutdown(req); | ||
| if (err === 1) // synchronous finish | ||
| return afterShutdown.call(req, 0); | ||
| // TODO: Why does this need to be in nextTick? | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @addaleax Maybe you have some insight here?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens when it isn’t? 😅
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! I forgot about that small detail: Path: parallel/test-http2-client-socket-destroy
Mismatched noop function calls. Expected exactly 1, actual 0.
at Object.mustCall (/Users/ronagy/GitHub/nxtedition/node/test/common/index.js:324:10)
at Http2Server.<anonymous> (/Users/ronagy/GitHub/nxtedition/node/test/parallel/test-http2-client-socket-destroy.js:19:29)
at Http2Server.<anonymous> (/Users/ronagy/GitHub/nxtedition/node/test/common/index.js:358:15)
at Http2Server.emit (events.js:304:20)
at ServerHttp2Session.sessionOnStream (internal/http2/core.js:2739:19)
at ServerHttp2Session.emit (events.js:304:20)
at emit (internal/http2/core.js:285:8)
at processTicksAndRejections (internal/process/task_queues.js:87:22)
Command: out/Release/node --expose-internals /Users/ronagy/GitHub/nxtedition/node/test/parallel/test-http2-client-socket-destroy.js
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like some form of timing issue. |
||
| process.nextTick(() => { | ||
| const req = new ShutdownWrap(); | ||
| req.oncomplete = afterShutdown; | ||
| req.callback = cb; | ||
| req.handle = handle; | ||
| const err = handle.shutdown(req); | ||
| if (err === 1) // synchronous finish | ||
| return afterShutdown.call(req, 0); | ||
| }); | ||
| } else { | ||
| cb(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this maybe be a good reason to keep
_finalbehind a nextTick, at least in a semver-patch PR? Or maybe, why does this need to be changed here but not in the other places where we use a similar pattern (e.g. net, http2)?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's one reason to keep
_finalbehind a nextTick but there are other reasons which make it not a good idea. I don't think this becomes a relevant problem once #29656 is merged.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should probably be changed in those places as well.