processEventsWhileBlocked not exception safe

Former-commit-id: 1ef187533c26bfa0c084a815b8b80de92ba1cf0b
This commit is contained in:
John Sully 2020-02-17 18:57:13 -05:00
parent 4d01660331
commit 96c4f5ecfc

View File

@ -3065,6 +3065,7 @@ void unpauseClientsIfNecessary()
* *
* The function returns the total number of events processed. */ * The function returns the total number of events processed. */
int processEventsWhileBlocked(int iel) { int processEventsWhileBlocked(int iel) {
serverAssert(GlobalLocksAcquired());
int iterations = 4; /* See the function top-comment. */ int iterations = 4; /* See the function top-comment. */
int count = 0; int count = 0;
@ -3074,7 +3075,11 @@ int processEventsWhileBlocked(int iel) {
serverAssert(c->flags & CLIENT_PROTECTED); serverAssert(c->flags & CLIENT_PROTECTED);
c->lock.unlock(); c->lock.unlock();
} }
aeReleaseLock(); aeReleaseLock();
serverAssertDebug(!GlobalLocksAcquired());
try
{
while (iterations--) { while (iterations--) {
int events = 0; int events = 0;
events += aeProcessEvents(g_pserver->rgthreadvar[iel].el, AE_FILE_EVENTS|AE_DONT_WAIT); events += aeProcessEvents(g_pserver->rgthreadvar[iel].el, AE_FILE_EVENTS|AE_DONT_WAIT);
@ -3082,6 +3087,18 @@ int processEventsWhileBlocked(int iel) {
if (!events) break; if (!events) break;
count += events; 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; AeLocker locker;
if (c != nullptr) if (c != nullptr)
c->lock.lock(); c->lock.lock();