Maybe we should have two different types of shutdowns? Analogous to the difference between 'kill' and 'kill -9'. If we wanted to have a really crude but effective approach:
// Increment this just before you start doing something you don't want a shutdown to leave partially done. // Decrement it when it is done or is abandoned due to error. std::atomic<unsigned> i_am_doing_something; std::atomic<bool> waiting_to_shut_down; You're not allowed to start anything new when waiting_to_shut_down is true. A normal shutdown would set waiting_to_shutdown to true, then wait for i_am_doing_something to be zero. In practice, i_am_doing_something should probably be a mutex-protected unordered_map. You put in source file name, line number and a cookie of some sort when you start something, remove this object when you're done. If the fail-safe timeout for a clean shutdown expired, ATS would log the contents of the i_am_doing_something map, and then shut down ugly. On Thu, Feb 28, 2019 at 11:17 AM Fei Deng <duke8...@apache.org> wrote: > void TSThreadSetCancelState(TSThread thread, int state); > void TSThreadSetCancelType(TSThread thread, int type); > void TSThreadCancel(TSThread thread); > void *TSThreadJoin(TSThread thread); > > Some plugins have been causing a lot of crashes during ATS shutdown, the > root cause is due plugin threads are not aware of ATS is shutting down and > still trying to do stuff such as initiating ssl handshake. The workaround > right now is to set a flag using the newly implemented > `SHUTDOWN_LIFECYCLE_HOOK`, but there will still be race conditions since > some threads have a very long turnaround time. > > These new APIs expose corresponding pthread calls so plugins can have a > better control of its own threads. >