S
S
Sirian2012-09-21 13:30:12
Node.js
Sirian, 2012-09-21 13:30:12

Node.JS: Socket Reuse

I'm trying to run this script:

require('net').createServer().listen('/tmp/test');


then terminate it and run it again, it will throw an error:
Error: listen EADDRINUSE

How to force node.js to reuse sockets? (for both local sockets and tcp sockets)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Shirokov, 2012-09-21
@kurokikaze

Due to TIME_WAIT, bind() on a socket may return EADDRINUSE for another 2-4 minutes. In general, node should not pay attention to this, because. all sockets are opened with SO_REUSEADDR.
In your case, you may be advised to do it first.require('fs').unlink('/tmp/test');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question