Re: Design Questions on Termination

On Dec 28, 9:45 am, Scott Gifford <sgiff...@xxxxxxxxxxxxxxxx> wrote:

Here's a possible solution for sockets. Instead of calling close() on
the file descriptor, Tm calls shutdown(). That leaves the file
descriptor around so the same fd number won't be assigned to a
different connection, but it will be in a state where select() will
find it readable, read will return 0, and write will fail. The child
should notice one of those conditions, and can then exit its select
loop and close the socket safely.

That's a common pattern and it definitely works, but I don't think it
will solve the race condition. If you call 'shutdown' without
synchronizing with the other thread, what happens in the following

1) You are about to call 'shutdown', you have made that decision.

2) The thread returns from 'select' because the connection you were
going to shutdown just happened to close normally from the other side.

3) That thread goes through its set and finds the connection shut down

4) It calls 'close'.

5) Something happens that results in a new connection being made or
accepted, it gets the same file descriptor as the thread closed in
step 4.

6) We go back to the 'shutdown' thread, and it shuts down the new
connection made in step 5.


So you have to synchronize with the thread that can call 'close' to
call 'shutdown' anyway. So how much does 'shutdown' help you? It will
get you out of 'select', but how do you know when it is safe to call


Relevant Pages

  • Re: Overlapped WSASend and IOCP
    ... If you want a graceful shutdown then you should call shutdown on the ... then wait for the other end of the connection to do the same. ... What is the best way to disconnect a client from the server. ... grab unsent data from the temporary buffer and retry to send it. ...
  • Re: BackgroundWorker in .NET CF 2.0
    ... ActiveSync 4.5 allows a WiFi connection while cradled. ... private void ManForm_Closing ... I'm making use of this handy utility so I can log debug messages to ... I even added a static ShutDown() method to the TcpTraceListener ...
  • Re: Frequent panics on Dell Latitude D610 running 6.1-STABLE GENERIC
    ... X connection to:0.0 broken (explicit kill or server shutdown). ...
  • RE: Does Socket.Shutdown or Socket.Close Block and when?
    ... receive a heartbeat message every 5 seconds on each socket (to make sure the ... connection is still up to each client). ... heartbeat within say 10 seconds then the server will proceed to shutdown the ... the send buffer is empty or becomes empty before the elapsed timeout. ...
  • Re: Network connection not getting enabled during shutdown
    ... before during shutdown. ... Your application or service prob will need to monitor the Windows ... monitor that up to the point windows terminates the network connections. ... I'd say it would be impossible to activate a connection once window has ...