Unhandled "Port Address already in use"
Describe the bug When running dice on a port that is already occupied by another process, dice simply exits without any error message or exit status.
To Reproduce Steps to reproduce the behavior:
- Run dice on a port that is already in use.

Expected behavior Dice exits with exit status 1 and an error message like "bind: Address already in use"
@arpitbbhayani can I try this one to start with. looks like a simple log change.
Go for it @ameyajoshi35
@arpitbbhayani @ameyajoshi35 it would be good if there would be a free port finder module which can be developed as a pluggable solution.
For instance, in development mode we can enable this module as there would be many instances where we would stop and restart the DB and but in production mode we can disable it.
@rohanverma94 let's have a set of ports that we check if none of them are free we panic. Otherwise that port is assigned. Whatvsay?
@arpitbbhayani yes this works, a must read regarding the problem - https://onlinehelp.opswat.com/centralmgmt/What_you_need_to_do_if_you_see_too_many_TIME_WAIT_sockets.html
@arpitbbhayani @rohanverma94 can you take a look at https://github.com/DiceDB/dice/pull/98 I was looking for a free port finder, we can add that as well but it picks up a random port. may be we can filter that as well. But as arpit suggested to keep it simple, I have added just a couple of ports and if in case unavailable in debug mode, code will try to start up on set of ports.
@ameyajoshi35 Well as @arpitbbhayani suggested you can further narrow down the search for free ports, you don't have to search on an infinite range. It would be more like doing a sequential port scan on a fixed range. The thing is even if some port is under "TIME_WAIT" then I can just try the next port. The extended problem of "TIME_WAIT" is based on TCP and something we can't get away from, we must have to wait till it is released by OS.
I manually mitigate the "address in use" problem (in case of wrong logic in process) -
I just kill via kill -9 <pid-of-7379>
However, it is tedious for development and hence I should be able to start the DB over a port range.
I realise that this thread has been idle for a while and this looks like a good first issue. Can I pick this up @arpitbbhayani ?
Hi, @arpitbbhayani @rohanverma94 shall I pick this up if it's still available ? 🚀
feel free to pick this up as my PR is not ready yet.
On Sun, Jun 11, 2023 at 7:20 PM Vibhav Tomar @.***> wrote:
Hi, @arpitbbhayani https://github.com/arpitbbhayani @rohanverma94 https://github.com/rohanverma94 shall I pick this up if it's still available ? 🚀
— Reply to this email directly, view it on GitHub https://github.com/DiceDB/dice/issues/95#issuecomment-1586174423, or unsubscribe https://github.com/notifications/unsubscribe-auth/AICFWHZKUDCOLCBQHIIUI4DXKXEKNANCNFSM6AAAAAAR44S4YI . You are receiving this because you were mentioned.Message ID: @.***>
Thank you for the heads up @ameyajoshi35
Hi, @arpitbbhayani @pranjal-verma @rohanverma94 Can you please check my PR and please review it once? #107