-
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
http_server: correct order prefinish
=>finish
#3059
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,23 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
const http = require('http'); | ||
|
||
var count = 0; | ||
const server = http.createServer(function(req, res) { | ||
const id = count++; | ||
setTimeout(function() { | ||
res.end('hello'); | ||
}, (2 - id) * 10); | ||
|
||
if (id === 1) | ||
server.close(); | ||
}).listen(common.PORT, function() { | ||
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.
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. @Fishrock123 I think this is way too much :) If this is not going to work - we are pretty much in a bad situation. What about verifying the Also, there is a possibly better fix for this: #3068 . |
||
const s = net.connect(common.PORT); | ||
|
||
const req = 'GET / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n'; | ||
const big = req + req; | ||
s.end(big); | ||
s.resume(); | ||
}); |
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 feel like if this is possible then there's something else wrong with the logic. From the documentation:
So how could this function ever be called more than once?
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 don't think this changes that logic. This change ensures that the prefinish event is actually emited before the finish event.
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. I'm trying to point out that it should be impossible to call this function twice. So the added check shouldn't be necessary.
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 is not about calling twice. It is about the order of events. The check handles the case where
finish
is emitted before theprefinish
was emitted.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.
This function is
finish()
. I find I confusing that it could be called in the preFinish case.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 is indeed very confusing because we don't use streams API for these events. We should move to them in the future. Feel free to open issue for this, @trevnorris