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. */
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();