-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
http2: no stream destroy while its data is on the wire #19002
Changes from 1 commit
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,62 @@ | ||
// Flags: --expose-gc | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const assert = require('assert'); | ||
const http2 = require('http2'); | ||
const makeDuplexPair = require('../common/duplexpair'); | ||
|
||
// Make sure the Http2Stream destructor works, since we don't clean the | ||
// stream up like we would otherwise do. | ||
process.on('exit', global.gc); | ||
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. I'm not sure I fully get why the explicit 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. @apapirovski Yea, I had to make changes to my original patch for this so that this So yes, it’s not needed, it’s just an extra test 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. Ok, awesome. Just wanted to make sure I wasn't missing anything. Thank you for replying. :) |
||
|
||
{ | ||
const { clientSide, serverSide } = makeDuplexPair(); | ||
|
||
let serverSideHttp2Stream; | ||
let serverSideHttp2StreamDestroyed = false; | ||
const server = http2.createServer(); | ||
server.on('stream', common.mustCall((stream, headers) => { | ||
serverSideHttp2Stream = stream; | ||
stream.respond({ | ||
'content-type': 'text/html', | ||
':status': 200 | ||
}); | ||
|
||
const originalWrite = serverSide._write; | ||
serverSide._write = (buf, enc, cb) => { | ||
if (serverSideHttp2StreamDestroyed) { | ||
serverSide.destroy(); | ||
serverSide.write = () => {}; | ||
} else { | ||
setImmediate(() => { | ||
originalWrite.call(serverSide, buf, enc, () => setImmediate(cb)); | ||
}); | ||
} | ||
}; | ||
|
||
// Enough data to fit into a single *session* window, | ||
// not enough data to fit into a single *stream* window. | ||
stream.write(Buffer.alloc(40000)); | ||
})); | ||
|
||
server.emit('connection', serverSide); | ||
|
||
const client = http2.connect('http://localhost:80', { | ||
createConnection: common.mustCall(() => clientSide) | ||
}); | ||
|
||
const req = client.request({ ':path': '/' }); | ||
|
||
req.on('response', common.mustCall((headers) => { | ||
assert.strictEqual(headers[':status'], 200); | ||
})); | ||
|
||
req.on('data', common.mustCallAtLeast(() => { | ||
if (!serverSideHttp2StreamDestroyed) { | ||
serverSideHttp2Stream.destroy(); | ||
serverSideHttp2StreamDestroyed = true; | ||
} | ||
})); | ||
} |
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.
Nit: can we put brackets around this multi-line block?
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.
@apapirovski Sure, done. We’re not that strict with that in the C++ parts usually
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.
I would prefer we were, haha. It's just easier to read :) Thanks!