Skip to content

net: multiple listen() events fail silently #6190

Closed
@trevnorris

Description

@trevnorris
  • Version: >= v4.x
  • Platform: All
  • Subsystem: net

It's possible to run listen() on a net.Server that's already listening to a port. The result is silent failure, with the side effect of changing the _connectionKey and or _pipeName.

More expected behavior would be to emit an error on the server's 'error' event handler.

Example test:

const assert = require('assert');
const net = require('net');
const server = net.createServer();
server.on('error', () => {
  process._rawDebug('server had an error');
});
server.listen(8080).listen(8081);
process.on('exit', () => {
  assert.equal(server.address().port, 8080);
  const key = server._connectionKey;
  assert.equal(key.substr(key.lastIndexOf(':')), ':8080');
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    netIssues and PRs related to the net subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions