Path: utzoo!attcan!uunet!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.programmer Subject: Re: Problem with binding of socket addresses Message-ID: <1990Dec10.194130.20414@athena.mit.edu> Date: 10 Dec 90 19:41:30 GMT References: Sender: news@athena.mit.edu (News system) Reply-To: jik@athena.mit.edu (Jonathan I. Kamens) Organization: Massachusetts Institute of Technology Lines: 40 In article , epeterso@houligan.encore.com (Eric Peterson) writes: |> However, the server occasionally hits a bug and core dumps or dies off |> in some other way. But it dies off and closes its end of the |> connection before the client closes the other end. When this occurs |> and I attempt to restart the server, the bind() call fails with the |> error "Address already in use". |> |> Now, neither the client nor the server is running at the time I try to |> restart the server, and there isn't a problem with address collisions |> with another process. As far as I can tell, nothing else is using |> this address. So why does bind() fail? In article , sean@ms.uky.edu (Sean Casey) writes: |> Set the "reuse address" socket option, between the socket() and the |> bind() calls. Then your program can always immediately restart. Sean's suggestion will solve the problem, but he does not explain why the problem occurs, so I guess I'll do that :-). The TCP protocol states that after a TCP stream connection has been closed abnormally, the same local/foreign port combination cannot be used again for (2 * MSL). MSL stands for the Maximum Segment Lifetime, which is usually set to a minute, which means that it probably takes about two minutes before the address is useable again. The reason for this is to make sure that all packets which were supposed to get to the old process connected to the socket don't accidentally get delivered to the new process instead -- the delay is long enough so that all the waiting packets should ge thrown away. Using the reuse address socket option will make it possible for you to rebind to the socket. It's also a violation of the TCP protocol. But what the hell, sometimes pragmatism has to win out over theory. This is definitely one of those times :-). -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710