1. Solution to "Address already in use" bind() problem?
Greetings netters -
I have a server application that does the common socket(), bind(),
accept() sequence, which usually works just fine.
However, in some situations after having restarted the program, the
bind() system call fails with the error "Address already in use". If I
wait about 2-3 minutes, the problem goes away.
Last time I investigated this, I was told that it is because the
socket on which the listener is running is not closed properly. Ok, so
I revised my code to make sure a close() is issued for the socket in
all cases. I still have the problem though.
The funny thing is, that if I CTRL-C kill the application, Idon't have
the problem, only if I shut down properly. (Perhaps CTRL-C forces the
kernel to clean up after the application, including any open sockets?)
I was also told, that the reason why the problem goes away after 2-3
minutes, is because this is a known problem under SysV, and there is a
built-in mechanism to "un-hang" hung ports to cope with this problem.
However, I'd really like to fix my app so it doesn't create this
problem following an orderly shutdown.
Any suggestions anyone?
TIA - Henrik
PS. I've tried the FAQ...
2. Memory max'ed problem
3. Help with "bind: Address already in use" errors
4. Questions & Answers
5. error in NAMED/BIND "Address already in use"
6. binary of new lynx for sparc solaris on a sunblade machine
7. bind error, "Address already in use"
8. FTP problem...
9. Getting error: "cpd bind address already in use"
10. "bind: Address already in use" error after 2.6 upgrade
11. error: could not bind to "IP" port 80 (Address already in use)
12. Identd "bind: Address already in use" messages in /var/log/messages
13. TCP/IP, bind() error, "address is already in use?"