In the last days I was going to spent some time debugging the random NEd Nim editor crashes. Unfortunately, while I got some crashes some weeks ago when working on the chess game, I was not able to generate crashes when testing. So I think I have to wait until a real crash occurs again, and then try to remember how it was generated...
One problem persists. That is terminating NEd and launching it again immediately. For this case the port is still in use, and communication with nimsuggest does not work. After about two minutes port is destroyed by OS and all works again.
That is a well known net communication problem of course, and not a big problem in real life. One solution is of course just waiting 2 minutes (can be up to 4 minutes from socket specs.) Another solution may be not using a fixed port number, but choosing one from a random range. But of course both is not nice. So I spent two hours for googling yesterday -- I found many questions with similar problems, but was not able to extract a solution. At least not a solution which works without modifiing nimsuggest. With modifying nimsuggest, there may be a few: Using port number 0, so that OS chooses a free port number. Or maybe ensuring that client always closes socket connection first. Or maybe setting SO_REUSEADDR flag before bind(). SO_LINGER flag with timeout 0 was also mentioned, but not recommended.
https://github.com/ngtk3/NEd $ ./ned test.nim Traceback (most recent call last) ned.nim(1362) showData net.nim(1520) connect os.nim(153) raiseOSError Error: unhandled exception: Connection refused [OSError]