How to reuse TCP listening socket immediately after it was connected at least once?

Thomas Bellman bellman at lysator.liu.se
Thu May 28 12:42:05 CEST 2009


Roy Smith <roy at panix.com> wrote:

> In article <gvb8fn$7gm$1 at lust.ihug.co.nz>,
> Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> wrote:

>> The right thing to do is try to ensure that all your connections are
>> properly closed at shutdown. That may not be enough (if your server crashes
>> due to bugs), so the other thing you need to do is retry the socket open,
>> say, at 30-second intervals, until it succeeds.

> That may be a reasonable thing to do for production code, but when you're
> building and debugging a server, it's a real pain to not be able to restart
> it quickly whenever you want (or need) to.

Speaking as a sysadmin, running applications for production,
programs not using SO_REUSEADDR should be taken out and shot.

You *can't* ensure that TCP connections are "properly closed".
For example, a *client* crashing, or otherwise becoming
unreachable, will leave TCP connections unclosed, no matter
what you do.

Not using SO_REUSEADDR means forcing a service interruption of
half an hour (IIRC) if for some reason the service must be
restarted, or having to reboot the entire machine.  No thanks.
I have been in that situation.


-- 
Thomas Bellman,   Lysator Academic Computer Club,   Linköping University
"Never let your sense of morals prevent you    !  Sweden ; +46-13 177780
 from doing what is right."  -- Salvor Hardin  !  bellman at lysator.liu.se



More information about the Python-list mailing list