EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: socket shutdown races?
From: Michael Davidsaver via Core-talk <[email protected]>
To: EPICS core-talk <[email protected]>
Date: Mon, 8 Jul 2019 20:05:19 -0700
Sorry for the stream of consciousness (aka ramble).  I've been digging into
this all day.  I thought I'd see if anyone else has run across
this situation before.

Looking into socket cleanup race conditions for
https://github.com/epics-base/pvAccessCPP/issues/149
has led me down an unexpected path.

In the process of understanding what actually go on when a
TCP connection is closed, and it's two worker thread exit,
I noticed a unit test hang.  I found that on RTEMS 4.10 (at least)
the worker thread handling TCP accept() apparently not being interrupted
correctly.  It's still in accept() after close() has returned in the other thread.

I noticed that the code trying to interrupt calls shutdown(fd, SHUT_RDWR)
and then immediately calls close(fd).  The calling thread has higher priority
than the worker.  I add a sleep 1 in between these two socket calls and the
accept() is interrupted and the worker returns.

That this hangs may well be an RTEMS bug, though it might be argued to be
undefined behavior.  It does seem to me like a race to close() when a
concurrent thread may be preparing to, or in the process of, calling eg. recv(),
accept(), or similar.

If so, how to avoid this without a redesign?  *

In the esscimqi_socketBothShutdownRequired cases (not winsock) I imagine
that the correct resolution is to shutdown(), then join the workers,
and finally to close().

What about Windows where only close() is called?  aka. esscimqi_socketCloseRequired


* eg. use select()/poll(), including a dedicated pipe() to cleanly interrupt

Replies:
Re: socket shutdown races? Michael Davidsaver via Core-talk

Navigate by Date:
Prev: Re: [Merge] ~freddie-akeroyd/epics-base:msi_close_file into epics-base:3.15 Andrew Johnson via Core-talk
Next: Re: [Merge] ~anj/epics-base/+git/base-3.15:decimate-filter into epics-base:3.15 Andrew Johnson via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Build completed: epics-base base-7.0-264 AppVeyor via Core-talk
Next: Re: socket shutdown races? Michael Davidsaver via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024 
ANJ, 09 Jul 2019 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·