Re: closing a server socket

From: Alex Martelli (aleax_at_aleax.it)
Date: 10/18/03


Date: Sat, 18 Oct 2003 17:38:09 GMT

simon place wrote:
   ...
> Yes, no problem closing a server before it returns to accept another
> connection, but when the handler is threaded,

When the server is threaded, it should be designed accordingly; see
Python's standard library, module SocketServer etc, for one right
way to design a threaded server.

> i.e. closing server socket does not unblock accept and you can still get
> connections on it!
> ( because it has not actually been closed!)
> how is this acceptable?

It's not: in general, two threads should NEVER access the same
resource simultaneously, unless the resource is specifically
known to be thread safe. sockets aren't. It's not acceptable,
and the bug is in the program which has one of its threads
make a sock.close() call while another is waiting on a
sock.accept() on the same socket sock.

> with socket modified to actually close the socket,
   ...
> i.e. close socket generates an exception on accept and no more
> connections.

On _your_ platform, no doubt. I'd bet substantial money that,
without even going to especially _exotic_ platforms, you'll find
terrible misbehavior with such mods on at least one of the
platforms I routinely program for.

> If there's some underlying difficulty that causes this to come back and
> bite the testing i've done shows this to take a very long time.

Just as much time as is necessary to go and purchase some
other platform to try it on, I suspect.

Alex



Relevant Pages

  • Establishing a p2p connection in python
    ... programming PHP on a webdeveloper basis. ... I thought that one approach could be to write a small server for my ... users and establishing p2p connections on demand. ... It would seem like the socket ...
    (comp.lang.python)
  • Re: NLB Cluster, service restart and persistant socket connection
    ... MVP - Windows Server - Clustering ... opening a persistent socket client to another server. ... incoming socket connections are coming in ...
    (microsoft.public.windows.server.clustering)
  • Re: receiving data over socket
    ... I want to print the data the server received. ... anyone can recommend a good VB2005 book that deals with socket programming I ... if your server needs to support multiple connections ... You aren't guarenteed to recieve all your data ...
    (microsoft.public.dotnet.languages.vb)
  • Re: MSDN Using Asynchronous Server Socket ?
    ... I properly shutdown the socket after receiving the message. ... The problem is in your server code that handles the active connection. ... framework doesn't handle a lot of "idle" connections very well. ... client disconnects, do you shutdown and then close the client socket? ...
    (microsoft.public.dotnet.framework)
  • Socket connections in TIME_WAIT and apache MaxClients setting
    ... of concurrent connections to the web server? ... BigIP were not responding to connections. ... I noted that a wc -l of socket ...
    (SunManagers)