Penguin
Annotated edit history of EADDRINUSE version 8, including all changes. View license author blame.
Rev Author # Line
1 WikiAdmin 1 !!!Address already in use
2
2 KevinGeorge 3 This error means an address is already in use, this is frequently due to a network port or socket being already claimed by another process. You can't have two processes listen on the same IP address/port pair at the same time unless they actively cooperate to do so. For example, when starting apache a second time without closing down the first connection you get in the logs:
7 PerryLorier 4 <pre>
1 WikiAdmin 5 Address already in use: make_sock: could not bind to port 80
7 PerryLorier 6 </pre>
1 WikiAdmin 7
8 You can tell whats listening on a port by using:
7 PerryLorier 9 <pre>
1 WikiAdmin 10 netstat -ap
7 PerryLorier 11 </pre>
1 WikiAdmin 12 (see netstat(8) for more information)
13
2 KevinGeorge 14 kill(1) the other program that is listening on that port and try again.
1 WikiAdmin 15
2 KevinGeorge 16 Usually you get this error when trying to start a daemon that is already running.
5 SamJansen 17
6 PerryLorier 18 This also occurs when a [TCP] socket is still timing out. If you stop a program that was listening then restart it again quickly, you may find you get this error. In this case either wait a few minutes (4 should do); or in the case that it is your own program; use the code below.
3 PerryLorier 19
20 ----
21 To code around this call
7 PerryLorier 22 <pre>
3 PerryLorier 23 unsigned int opt = 1;
24 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))==-1) {
25 perror("setsockopt(fd,SOL_SOCKET, SO_REUSEADDR,1)");
8 PerryLorier 26 ~exit(1);
3 PerryLorier 27 }
7 PerryLorier 28 </pre>
29
30 ----
31
32 Another cause of this is that you have run out of spare addresses in the euphemeral port range. if you call bind(2) with a port of 0, then the kernel will choose a port out of the euphemeral port range. If there are no spare ports in this range you may get an "Address already in use" error. Under linux you can change which ports are available to be used as ephemeral ports with the <tt>net.ipv4.ip_local_port_range</tt> sysctl.