bneradt opened a new pull request, #13556:
URL: https://github.com/apache/trafficserver/pull/13556

   A __shutdown__ function usually releases process global resources, and
   often does so through FFI into a native library. The shutdown handler
   locked only the state it was calling the function on and released that
   lock before moving to the next state, so the callback running in state 0
   could tear those resources down while a request callback was still using
   them in state 1. Production has crashed this way during restart, inside
   a global read-request callback rather than in any shutdown path.
   
   Locking every Lua state for the duration of the callbacks is what makes
   __shutdown__ exclusive with all Lua code, but the lifecycle thread
   cannot be the one holding those locks: ProxyMutex is recursive per event
   thread, so that thread still enters Lua itself when it returns to its
   event loop for a final iteration. This patch therefore hands the
   callbacks to a thread of its own, which acquires every main state mutex
   before invoking any __shutdown__ function and keeps the global ones for
   the rest of the process lifetime, so no queued callback can enter Lua
   after the resources it uses are gone. Acquisition is bounded, and the
   callbacks are skipped with an error rather than run against a state that
   never went idle. The remap state mutexes are given back once the
   callbacks are done, because ATS destroys the remap instances after this
   hook and that path takes those same mutexes.
   
   The callbacks for every script are also invoked from a single
   continuation now, so that the states are quiesced exactly once no matter
   how many scripts define __shutdown__.
   
   The gold test drives requests through a second Lua state across the
   shutdown and fails if a __shutdown__ function overlaps one, or if any
   Lua runs after the callbacks.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to