Skip to content
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: revert #14024 writable is never set to false #15404

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,6 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
this.connection.uncork();

this.finished = true;
this.writable = false;

// There is the first message on the outgoing queue, and we've sent
// everything to the socket.
Expand Down
13 changes: 10 additions & 3 deletions test/parallel/test-http-outgoing-finish-writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ const assert = require('assert');
const http = require('http');

// Verify that after calling end() on an `OutgoingMessage` (or a type that
// inherits from `OutgoingMessage`), its `writable` property is set to false.
// inherits from `OutgoingMessage`), its `writable` property is not set to false

const server = http.createServer(common.mustCall(function(req, res) {
assert.strictEqual(res.writable, true);
assert.strictEqual(res.finished, false);
res.end();
assert.strictEqual(res.writable, false);

// res.writable is set to false after it has finished sending
// Ref: https://github.com/nodejs/node/issues/15029
assert.strictEqual(res.writable, true);
assert.strictEqual(res.finished, true);

server.close();
Expand All @@ -27,5 +30,9 @@ server.on('listening', common.mustCall(function() {

assert.strictEqual(clientRequest.writable, true);
clientRequest.end();
assert.strictEqual(clientRequest.writable, false);

// writable is still true when close
// THIS IS LEGACY, we cannot change it
// unless we break error detection
assert.strictEqual(clientRequest.writable, true);
}));
35 changes: 35 additions & 0 deletions test/parallel/test-http-writable-true-after-close.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const { get, createServer } = require('http');

// res.writable should not be set to false after it has finished sending
// Ref: https://github.com/nodejs/node/issues/15029

let external;

// Http server
const internal = createServer((req, res) => {
res.writeHead(200);
setImmediate(common.mustCall(() => {
external.abort();
res.end('Hello World\n');
}));
}).listen(0);

// Proxy server
const server = createServer(common.mustCall((req, res) => {
get(`http://127.0.0.1:${internal.address().port}`, common.mustCall((inner) => {
res.on('close', common.mustCall(() => {
assert.strictEqual(res.writable, true);
}));
inner.pipe(res);
}));
})).listen(0, () => {
external = get(`http://127.0.0.1:${server.address().port}`);
external.on('error', common.mustCall((err) => {
server.close();
internal.close();
}));
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
'use strict';
const common = require('../common');
const http = require('http');
const assert = require('assert');
const util = require('util');
const stream = require('stream');

// Verify that when piping a stream to an `OutgoingMessage` (or a type that
// inherits from `OutgoingMessage`), if data is emitted after the
// `OutgoingMessage` was closed - no `write after end` error is raised (this
// should be the case when piping - when writing data directly to the
// `OutgoingMessage` this error should be raised).
// `OutgoingMessage` was closed - a `write after end` error is raised

function MyStream() {
stream.call(this);
Expand All @@ -22,8 +21,10 @@ const server = http.createServer(common.mustCall(function(req, res) {
process.nextTick(common.mustCall(() => {
res.end();
myStream.emit('data', 'some data');
res.on('error', common.mustCall(function(err) {
assert.strictEqual(err.message, 'write after end');
}));

// If we got here - 'write after end' wasn't raised and the test passed.
process.nextTick(common.mustCall(() => server.close()));
}));
}));
Expand Down