Shutdown hook should grab the lock if there is one#4919
Shutdown hook should grab the lock if there is one#4919shinrich merged 1 commit intoapache:masterfrom
Conversation
|
Talk to @shinrich - she had the same problem and we tweaked a call (I think the mutex locking) to transparently deal with null mutexes. Also, please work with @dyrock on plugin coordination - one of the points of that is to unify this kind of code so bugs like this don't have to stepped on one place at a time. |
|
Yes, we tidied up the mutex try lock to gracefully handle the null mutex case. Need to remember where we made that change. |
|
See #4926. |
1ecc844 to
b6bf972
Compare
| APIHook *hook = lifecycle_hooks->get(TS_LIFECYCLE_SHUTDOWN_HOOK); | ||
| while (hook) { | ||
| hook->invoke(TS_EVENT_LIFECYCLE_SHUTDOWN, nullptr); | ||
| if (hook->m_cont->mutex) { |
There was a problem hiding this comment.
Why not
while (hook) {
SCOPED_MUTEX_LOCK(lock, hook->m_cont->mutex, this_ethread());
hook->invoke(TS_EVENT_LIFECYCLE_SHUTDOWN, nullptr);
hook = hook->next;
}
?
There was a problem hiding this comment.
So the lock object will be a harmless do-nothing if the mutex is null?
There was a problem hiding this comment.
Yes. It was designed that way precisely to get this effect. Better to check the null in one place, and not every callsite.
There was a problem hiding this comment.
To be OCD about not holding mutexes longer than necessary, I would prefer:
while (hook) {
{
SCOPED_MUTEX_LOCK(lock, hook->m_cont->mutex, this_ethread());
hook->invoke(TS_EVENT_LIFECYCLE_SHUTDOWN, nullptr);
}
hook = hook->next;
}
There was a problem hiding this comment.
It's during shutdown, I think I want it to hold it for longer, might expose other problems in the code.
b6bf972 to
6eab7b3
Compare
6eab7b3 to
6ab78ee
Compare
This was causing some crashes during shutdown.