Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EADDRINUSE after force-quitting stub-rpc-server #2

Open
tinybike opened this issue Mar 27, 2017 · 3 comments
Open

EADDRINUSE after force-quitting stub-rpc-server #2

tinybike opened this issue Mar 27, 2017 · 3 comments

Comments

@tinybike
Copy link
Member

Getting an unusual error from ethrpc's tests. I force-quit (CTRL+C) the test suite during a run-thru and now I get the following error:

  1) tests that work against any node (test or live) IPC "before each" hook:
     Uncaught Error: listen EADDRINUSE testrpc.ipc
      at Object.exports._errnoException (util.js:1022:11)
      at exports._exceptionWithHostPort (util.js:1045:20)
      at Server._listen2 (net.js:1249:19)
      at listen (net.js:1298:10)
      at Server.listen (net.js:1382:7)
      at new IpcServer (node_modules/ethereumjs-stub-rpc-server/source/ipc-server.js:38:25)
      at Object.createStubServer (node_modules/ethereumjs-stub-rpc-server/source/index.js:8:14)
      at Context.<anonymous> (test/any-node.js:14:29)

(Not sure if this is an ethrpc issue or an ethereumjs-stub-rpc-server issue.)

@MicahZoltu
Copy link
Contributor

I suspect this is OS dependent. The stub server binds to a particular address (usually 1337) and if the underlying OS doesn't release that binding when the process is killed then the subsequent run will fail due to port in use. It also depends on what exactly a ctrl+c does on the OS in question. In *nix it sends a SIGINT signal, which the stub server could catch, manually unbind the ports, then process exit. However, you can only have a single SIGINT handler in your entire node application and having that handler in a library would be very bad form. We could put the handler in the ethrpc test suite and then have that call server.destroy. This would require adding a sigint handler to every describe in ethrpc tests that use the stub server I believe. I believe the most correct place for this would be in Mocha, but it appears that they decided not to handle SIGINT because they couldn't guarantee it would run correctly (we would have the same problem if we tried to implement it ourselves).

If you wait a couple minutes (for timeouts) does the port eventually get opened up so it can be re-used?

I don't believe the effort required to fix this is worth the gains since this is a transient problem that occurs when you SIGINT tests in the middle of a run, and making the tests robust against this kind of interruption is fairly costly.

@tinybike
Copy link
Member Author

If you wait a couple minutes (for timeouts) does the port eventually get opened up so it can be re-used?

It does not. It's been a couple days now and the port never opens up again. Is it possible to pre-emptively unbind the ports before the tests are run, in case the tests don't exit cleanly?

@MicahZoltu
Copy link
Contributor

MicahZoltu commented Mar 28, 2017

No, I actually ran into this issue (port in use by killed process) for other reasons and apparently on Linux there is no to force the unbinding of a port and the OS never cleans up used ports.

Out of curiosity, if you ask the OS what is using port 1337, 1338, 2337, 2338 what does it say? I wonder if you have a process still running that actually has the port bound? The OS should have timed out the socket after a minute or two (assuming defaults and linux).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants