Skip to content

net: writable is not set to false after socket has ended #36029

@mscdex

Description

@mscdex
  • Version: v15.0.0-v15.1.0, master
  • Platform: Linux
  • Subsystem: net

What steps will reproduce the bug?

const net = require('net');

net.createServer(function(s) {
  this.close();
  s.end();
}).listen(0, 'localhost', function() {
  const socket = net.connect(this.address().port, 'localhost');
  socket.on('end', () => {
    console.log('socket.writable', socket.writable);
    if (socket.writable)
      socket.write('hello world');
  });
});

How often does it reproduce? Is there a required condition?

Every time.

What is the expected behavior?

No error emitted on the socket.

Output (on node v14.x and earlier):

socket.writable false

What do you see instead?

Output:

socket.writable true
node:events:304
      throw er; // Unhandled 'error' event
      ^

Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (node:net:443:14)
    at Socket.<anonymous> (/tmp/test.js:11:14)
    at Socket.emit (node:events:339:22)
    at endReadableNT (node:internal/streams/readable:1289:12)
    at processTicksAndRejections (node:internal/process/task_queues:80:21)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:188:8)
    at emitErrorCloseNT (node:internal/streams/destroy:153:3)
    at processTicksAndRejections (node:internal/process/task_queues:80:21) {
  code: 'EPIPE'
}

Additional information

The description for writable.writable in the streams docs reads:

Is true if it is safe to call writable.write(), which means the stream has not been destroyed, errored or ended.

So I believe this is a regression.

/cc @nodejs/net

Metadata

Metadata

Assignees

No one assigned

    Labels

    netIssues and PRs related to the net subsystem.regressionIssues related to regressions.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions