-
Notifications
You must be signed in to change notification settings - Fork 30k
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: OutgoingMessage change writable after end #14024
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,26 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
const server = http.createServer(common.mustCall(function(req, res) { | ||
assert(res.writable, 'Res should be writable when it is received \ | ||
and opened.'); | ||
assert(!res.finished, 'Res shouldn\'t be finished when it is received \ | ||
and opened.'); | ||
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. Can you use |
||
res.end(); | ||
assert(!res.writable, 'Res shouldn\'t be writable after it was closed.'); | ||
assert(res.finished, 'Res should be finished after it was closed.'); | ||
|
||
server.close(); | ||
})); | ||
|
||
server.listen(0); | ||
|
||
server.on('listening', common.mustCall(function() { | ||
http.request({ | ||
port: server.address().port, | ||
method: 'GET', | ||
path: '/' | ||
}).end(); | ||
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 |
||
})); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const http = require('http'); | ||
const OutgoingMessage = require('_http_outgoing').OutgoingMessage; | ||
|
||
const server = http.createServer(common.mustCall(function(req, res) { | ||
console.log('Got a request, piping an OutgoingMessage to it.'); | ||
const outgointMessage = new OutgoingMessage(); | ||
outgointMessage.pipe(res); | ||
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. I agree. I chose I guess this should either be disabled (by throwing an exception as you suggested), or it should work.
For more detailed explanation you can read my reply: #14024 (comment) |
||
|
||
setTimeout(() => { | ||
console.log('Closing response.'); | ||
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. can you remove the |
||
res.end(); | ||
outgointMessage.emit('data', 'some data'); | ||
|
||
// If we got here - 'write after end' wasn't raised and the test passed. | ||
setTimeout(() => server.close(), 10); | ||
}, 10); | ||
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. This is going to be very flaky. Can you refactor the test to not rely on timers? 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. Sure thing. I totally agree with you. Basically I needed |
||
|
||
setInterval(() => { | ||
console.log('Emitting some data to outgointMessage'); | ||
outgointMessage.emit('data', 'some data'); | ||
}, 1).unref(); | ||
|
||
})); | ||
|
||
server.listen(0); | ||
|
||
server.on('listening', common.mustCall(function() { | ||
http.request({ | ||
port: server.address().port, | ||
method: 'GET', | ||
path: '/' | ||
}).end(); | ||
})); |
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.
can you add a little comment explaining what this test is about here?