From 96c4f5ecfc64f2f4d5d467b7c56cbc02198b939c Mon Sep 17 00:00:00 2001 From: John Sully Date: Mon, 17 Feb 2020 18:57:13 -0500 Subject: [PATCH] processEventsWhileBlocked not exception safe Former-commit-id: 1ef187533c26bfa0c084a815b8b80de92ba1cf0b --- src/networking.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/networking.cpp b/src/networking.cpp index 9d94f5171..803edb5ac 100644 --- a/src/networking.cpp +++ b/src/networking.cpp @@ -3065,6 +3065,7 @@ void unpauseClientsIfNecessary() * * The function returns the total number of events processed. */ int processEventsWhileBlocked(int iel) { + serverAssert(GlobalLocksAcquired()); int iterations = 4; /* See the function top-comment. */ int count = 0; @@ -3074,14 +3075,30 @@ int processEventsWhileBlocked(int iel) { serverAssert(c->flags & CLIENT_PROTECTED); c->lock.unlock(); } + aeReleaseLock(); - while (iterations--) { - int events = 0; - events += aeProcessEvents(g_pserver->rgthreadvar[iel].el, AE_FILE_EVENTS|AE_DONT_WAIT); - events += handleClientsWithPendingWrites(iel); - if (!events) break; - count += events; + serverAssertDebug(!GlobalLocksAcquired()); + try + { + while (iterations--) { + int events = 0; + events += aeProcessEvents(g_pserver->rgthreadvar[iel].el, AE_FILE_EVENTS|AE_DONT_WAIT); + events += handleClientsWithPendingWrites(iel); + if (!events) break; + count += events; + } } + catch (...) + { + // Caller expects us to be locked so fix and rethrow + AeLocker locker; + if (c != nullptr) + c->lock.lock(); + locker.arm(c); + locker.release(); + throw; + } + AeLocker locker; if (c != nullptr) c->lock.lock();