-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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 missing close event on aborted response #1373
Closed
Closed
Changes from all commits
Commits
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
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,88 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var http = require('http'); | ||
|
||
var clientRequest = null; | ||
var serverResponseFinishedOrClosed = 0; | ||
var testTickCount = 3; | ||
|
||
var server = http.createServer(function (req, res) { | ||
console.log('server: request'); | ||
|
||
res.on('finish', function () { | ||
console.log('server: response finish'); | ||
serverResponseFinishedOrClosed++; | ||
}); | ||
res.on('close', function () { | ||
console.log('server: response close'); | ||
serverResponseFinishedOrClosed++; | ||
}); | ||
|
||
console.log('client: aborting request'); | ||
clientRequest.abort(); | ||
|
||
var ticks = 0; | ||
function tick() { | ||
console.log('server: tick ' + ticks + (req.connection.destroyed ? ' (connection destroyed!)' : '')); | ||
|
||
if (ticks < testTickCount) { | ||
ticks++; | ||
setImmediate(tick); | ||
} else { | ||
sendResponse(); | ||
} | ||
} | ||
tick(); | ||
|
||
function sendResponse() { | ||
console.log('server: sending response'); | ||
res.writeHead(200, {'Content-Type': 'text/plain'}); | ||
res.end('Response\n'); | ||
console.log('server: res.end() returned'); | ||
|
||
handleResponseEnd(); | ||
} | ||
}); | ||
|
||
server.on('listening', function () { | ||
console.log('server: listening on port ' + common.PORT); | ||
console.log('-----------------------------------------------------'); | ||
startRequest(); | ||
}); | ||
|
||
server.on('connection', function (connection) { | ||
console.log('server: connection'); | ||
connection.on('close', function () { console.log('server: connection close'); }); | ||
}); | ||
|
||
server.on('close', function () { | ||
console.log('server: close'); | ||
}); | ||
|
||
server.listen(common.PORT); | ||
|
||
function startRequest() { | ||
console.log('client: starting request - testing with ' + testTickCount + ' ticks after abort()'); | ||
serverResponseFinishedOrClosed = 0; | ||
|
||
var options = {port: common.PORT, path: '/'}; | ||
clientRequest = http.get(options, function () {}); | ||
clientRequest.on('error', function () {}); | ||
} | ||
|
||
function handleResponseEnd() { | ||
setImmediate(function () { | ||
setImmediate(function () { | ||
assert.equal(serverResponseFinishedOrClosed, 1, 'Expected either one "finish" or one "close" event on the response for aborted connections (got ' + serverResponseFinishedOrClosed + ')'); | ||
console.log('server: ended request with correct finish/close event'); | ||
console.log('-----------------------------------------------------'); | ||
|
||
if (testTickCount > 0) { | ||
testTickCount--; | ||
startRequest(); | ||
} else { | ||
server.close(); | ||
} | ||
}); | ||
}); | ||
} |
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.
usually, passing tests should be silent; could you remove the expected
console.log
s?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.
Of course I could remove them - I kept with the other tests which also contain
console.log
s (output is hidden anyway in normal test run).I thought, especially race conditions are much more understandable with some debugging output - also for future refactoring/debugging.
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.
Please keep them for now :) I've a bit delayed this, but going to review it next week!