Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 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
7 changes: 6 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const {
NumberParseInt,
ObjectDefineProperty,
ObjectSetPrototypeOf,
ReflectApply,
Symbol,
} = primordials;

Expand Down Expand Up @@ -434,6 +435,11 @@ function afterShutdown() {
// of the other side sending a FIN. The standard 'write after end'
// is overly vague, and makes it seem like the user's code is to blame.
function writeAfterFIN(chunk, encoding, cb) {
if (!this.writabledEnded) {
return ReflectApply(
stream.Duplex.prototype.write, this, [chunk, encoding, cb]);
}

if (typeof encoding === 'function') {
cb = encoding;
encoding = null;
Expand Down Expand Up @@ -947,7 +953,6 @@ Socket.prototype.connect = function(...args) {
this._unrefTimer();

this.connecting = true;
this.writable = true;

if (pipe) {
validateString(path, 'options.path');
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-net-writable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');

const server = net.createServer(common.mustCall(function(s) {
server.close();
s.end();
})).listen(0, 'localhost', common.mustCall(function() {
const socket = net.connect(this.address().port, 'localhost');
socket.on('end', common.mustCall(() => {
assert.strictEqual(socket.writable, true);
socket.write('hello world');
}));
}));