Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Cannot catch EADDRINUSE #184

@c7hm4r

Description

@c7hm4r

Hello! I want to implement that a different port is tried automatically when the currently tried out port is in use. However, it is impossible to catch the EADDRINUSE exception when running await node.start();. NodeJS terminates before node.start() returns a Promise.

Following is output:

node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::8000
    at Server.setupListenHandle [as _listen2] (node:net:1485:16)
    at listenInCluster (node:net:1533:12)
    at Server.listen (node:net:1621:7)
    at file:///project/node_modules/it-ws/dist/src/server.js:14:25
    at new Promise (<anonymous>)
    at Server.listen (file:///project/node_modules/it-ws/dist/src/server.js:12:22)
    at WebSocketListener.listen (file:///project/node_modules/@libp2p/websockets/dist/src/listener.js:72:27)
    at DefaultTransportManager.listen (file:///project/node_modules/libp2p/dist/src/transport-manager.js:155:37)
    at DefaultTransportManager.start (file:///project/node_modules/libp2p/dist/src/transport-manager.js:44:20)
    at file:///project/node_modules/@libp2p/components/dist/src/index.js:67:29
Emitted 'error' event on WebSocketServer instance at:
    at Server.emit (node:events:513:28)
    at emitErrorNT (node:net:1512:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '::',
  port: 8000
}

Node.js v18.9.0

To me, the issue has a medium severity, because the workaround to check the port usage before is tedious, platform dependent, and cannot be reliable because it is not atomic.

Versions:

  • Node.js: 18.9.0
  • libp2p: 0.39.1
  • @libp2p/websockets: 3.0.3

Possibly related:

Metadata

Metadata

Assignees

Labels

P2Medium: Good to have, but can wait until someone steps upexp/beginnerCan be confidently tackled by newcomersgood first issueGood issue for new contributorshelp wantedSeeking public contribution on this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions