-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
http: fix no dumping after maybeReadMore
#7211
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const http = require('http'); | ||
|
||
let onPause = null; | ||
|
||
const server = http.createServer((req, res) => { | ||
if (req.method === 'GET') | ||
return res.end(); | ||
|
||
res.writeHead(200); | ||
res.flushHeaders(); | ||
|
||
req.connection.on('pause', () => { | ||
res.end(); | ||
onPause(); | ||
}); | ||
}).listen(common.PORT, common.mustCall(() => { | ||
const agent = new http.Agent({ | ||
maxSockets: 1, | ||
keepAlive: true | ||
}); | ||
|
||
const post = http.request({ | ||
agent: agent, | ||
method: 'POST', | ||
port: common.PORT, | ||
}, common.mustCall((res) => { | ||
res.resume(); | ||
|
||
post.write(Buffer.alloc(16 * 1024).fill('X')); | ||
onPause = () => { | ||
post.end('something'); | ||
}; | ||
})); | ||
|
||
/* What happens here is that the server `end`s the response before we send | ||
* `something`, and the client thought that this is a green light for sending | ||
* next GET request | ||
*/ | ||
post.write('initial'); | ||
|
||
http.request({ | ||
agent: agent, | ||
method: 'GET', | ||
port: common.PORT, | ||
}, common.mustCall((res) => { | ||
server.close(); | ||
res.connection.end(); | ||
})).end(); | ||
})); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Out of curiosity, would there be a behavioral difference if you dropped the if statement and wrote it as
this._readableState.readingMore = this._consuming;
?Also, this could use a comment explaining why it's necessary to fiddle with
this._readableState
and whythis._consuming
should be true when monkey-patchingthis.read.
.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.
Yeah, I believe it would make a difference.
_consuming
can flip only intotrue
, and can't really go back. This is a hack to detect following scenario:Clearly in this case no one has attempted to read from
req
. Thus_consuming
isfalse
here, and in_http_server.js
the request can be_dump
ed. However, initial version (prior to this patch) of this hack wasn't working as expected, because_stream_readable.js
may call.read()
by itself. Luckily it calls it only frommaybeReadMore
, so we could test it here.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.
Okay, does that mean that in practice
this._readableState.readingMore
can be false whenthis._consuming
is true?A comment in the source explaining all that would definitely be appreciated. :-)
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.
Yes, it can be
false
._stream_readable.js
flips it on and off.