From 8a572eebf89d41326565bd0f8dae60f934f7c312 Mon Sep 17 00:00:00 2001 From: Susan Hinrichs Date: Fri, 17 Jan 2020 14:31:37 +0000 Subject: [PATCH] Avoid cross-thread mutex conflicts --- iocore/eventsystem/P_UnixEventProcessor.h | 2 -- iocore/eventsystem/UnixEThread.cc | 9 ++++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/iocore/eventsystem/P_UnixEventProcessor.h b/iocore/eventsystem/P_UnixEventProcessor.h index 2110fc14d1e..fe89945458b 100644 --- a/iocore/eventsystem/P_UnixEventProcessor.h +++ b/iocore/eventsystem/P_UnixEventProcessor.h @@ -115,8 +115,6 @@ EventProcessor::schedule(Event *e, EventType etype) if (e->continuation->mutex) { e->mutex = e->continuation->mutex; - } else { - e->mutex = e->continuation->mutex = e->ethread->mutex; } e->ethread->EventQueueExternal.enqueue(e); return e; diff --git a/iocore/eventsystem/UnixEThread.cc b/iocore/eventsystem/UnixEThread.cc index 2913ba6f86a..88f23f6f5fd 100644 --- a/iocore/eventsystem/UnixEThread.cc +++ b/iocore/eventsystem/UnixEThread.cc @@ -34,6 +34,8 @@ #include #endif +#include + struct AIOCallback; #define NO_HEARTBEAT -1 @@ -108,7 +110,7 @@ void EThread::process_event(Event *e, int calling_code) { ink_assert((!e->in_the_prot_queue && !e->in_the_priority_queue)); - MUTEX_TRY_LOCK(lock, e->mutex, this); + WEAK_MUTEX_TRY_LOCK(lock, e->mutex, this); if (!lock.is_locked()) { e->timeout_at = cur_time + DELAY_FOR_RETRY; EventQueueExternal.enqueue_local(e); @@ -120,6 +122,11 @@ EThread::process_event(Event *e, int calling_code) Continuation *c_temp = e->continuation; // Make sure that the continuation is locked before calling the handler + // Give a heads up if we are processing through a continuation without a mutex + if (!e->mutex) { + Warning("event processing for continuation %s without a mutex", typeid(*c_temp).name()); + } + // Restore the client IP debugging flags set_cont_flags(e->continuation->control_flags);