question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Repetitive EADDRINUSE when two responders start at the same time

See original GitHub issue
const cote = require('cote');
const responder = new cote.Responder({name: 'responder'});
const responder2 = new cote.Responder({name: 'responder 2'});

Running DEBUG=* node index.js on a new buster vagrant VM with nodejs installed leads to this:

Fri, 30 Aug 2019 01:49:07 GMT portfinder:defaultHosts exports._defaultHosts is: [ '0.0.0.0', '127.0.0.1', '::1', '10.0.2.15', 'fe80::a00:27ff:fe8d:c04d', null ]
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is 0.0.0.0
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 0.0.0.0 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is 0.0.0.0
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 0.0.0.0 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK 0.0.0.0 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is 127.0.0.1
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 127.0.0.1 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): failed 0.0.0.0 w/ port 8000 with error EADDRINUSE
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 0.0.0.0 port 8001
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK 127.0.0.1 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is ::1
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying ::1 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK 0.0.0.0 port 8001
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8001
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is 127.0.0.1
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 127.0.0.1 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK ::1 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is 10.0.2.15
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 10.0.2.15 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK 127.0.0.1 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is ::1
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying ::1 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK 10.0.2.15 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is fe80::a00:27ff:fe8d:c04d
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying fe80::a00:27ff:fe8d:c04d port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK ::1 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is 10.0.2.15
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 10.0.2.15 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): failed fe80::a00:27ff:fe8d:c04d w/ port 8000 with error EINVAL
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with an err: EINVAL
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() result callback: err is { Error: listen EINVAL: invalid argument fe80::a00:27ff:fe8d:c04d:8000
    at Server.setupListenHandle [as _listen2] (net.js:1260:19)
    at listenInCluster (net.js:1325:12)
    at doListen (net.js:1458:7)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
  code: 'EINVAL',
  errno: 'EINVAL',
  syscall: 'listen',
  address: 'fe80::a00:27ff:fe8d:c04d',
  port: 8000 }
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is 0.0.0.0
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 0.0.0.0 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK 10.0.2.15 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is null
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying null port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK null port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is undefined
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying undefined port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): failed 0.0.0.0 w/ port 8000 with error EADDRINUSE
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 0.0.0.0 port 8001
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK undefined port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() result callback: openPorts is [ 8000, 8000, 8000, 8000, 8000, 8001 ]
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is 0.0.0.0
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 0.0.0.0 port 8001
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK 0.0.0.0 port 8001
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8001
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is 127.0.0.1
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 127.0.0.1 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): failed 0.0.0.0 w/ port 8001 with error EADDRINUSE
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 0.0.0.0 port 8002
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK 127.0.0.1 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is ::1
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying ::1 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK 0.0.0.0 port 8002
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8002
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is 127.0.0.1
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 127.0.0.1 port 8001
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK ::1 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is 10.0.2.15
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 10.0.2.15 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK 127.0.0.1 port 8001
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8001
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is ::1
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying ::1 port 8001
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK 10.0.2.15 port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is null
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying null port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK ::1 port 8001
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8001
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback: host is 10.0.2.15
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort entered testPort(): trying 10.0.2.15 port 8001
Fri, 30 Aug 2019 01:49:07 GMT portfinder:testPort done w/ testPort(): OK null port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() iteration callback testPort() callback with a success for port 8000
Fri, 30 Aug 2019 01:49:07 GMT portfinder:getPort in eachSeries() result callback: openPorts is [ 8000, 8000, 8000, 8000, 8001 ]

(it runs indefinitely like this, except port numbers get higher and higher. Sometimes it will eventually die with “Killed”)

A setTimeout(func, 0) is enough to stop this from occurring. I’m assuming this is because the two Responders are constantly fighting for an unused port.

This is the same for a Responder and Publisher.

It’d probably be better to try a random port to stop this from happening.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dasherswcommented, Dec 25, 2019

to re-iterate, this is not actually an error, and doesn’t cause any issues, not even log, until you log every single thing.

0reactions
dasherswcommented, Dec 25, 2019

It’s basically the same mechanism. From the readme of get-port:

There is a very tiny chance of a race condition if another process starts using the same port number as you in between the time you get the port number and you actually start using it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NodeJs throws an EADDRINUSE error - Stack Overflow
1 Answer 1 ... It means some other process is already listening on that port. You might try executing something like sudo netstat...
Read more >
RabbitMQ fails to restart because of "eaddrinuse" error
We are running three rabbitmq nodes in one cluster. Sometimes rabbitmq fails to start after gracefully stop the service because of this error:....
Read more >
default port should no longer be 55555 #222 - GitHub
Expected Behavior / Situation webpack-serve should just work without config on macos Actual Behavior / Situation port 55555 is now in use on ......
Read more >
15 Common Error Codes in Node.js and How to Fix Them
1. ECONNRESET. ECONNRESET is a common exception that occurs when the TCP connection to another server is closed abruptly, usually before a ...
Read more >
CPR for the Professional Rescuer with AED and Standard ...
Two person CPR for child and infant is 15 compressions to 2 breaths. • Pulse check for adult and ... Recognition, response and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found