diff --git a/src/server.c b/src/server.c index 3c1f1cb6b..f30d33555 100644 --- a/src/server.c +++ b/src/server.c @@ -2306,15 +2306,17 @@ void beforeSleep(struct aeEventLoop *eventLoop) { /* Close clients that need to be closed asynchronous */ freeClientsInAsyncFreeQueue(); + /* Try to process blocked clients every once in while. Example: A module + * calls RM_SignalKeyAsReady from within a timer callback (So we don't + * visit processCommand() at all). */ + handleClientsBlockedOnKeys(); + /* Before we are going to sleep, let the threads access the dataset by * releasing the GIL. Redis main thread will not touch anything at this * time. */ if (moduleCount()) moduleReleaseGIL(); - /* Try to process blocked clients every once in while. Example: A module - * calls RM_SignalKeyAsReady from within a timer callback (So we don't - * visit processCommand() at all). */ - handleClientsBlockedOnKeys(); + /* Do NOT add anything below moduleReleaseGIL !!! */ } /* This function is called immediately after the event loop multiplexing @@ -2323,6 +2325,9 @@ void beforeSleep(struct aeEventLoop *eventLoop) { void afterSleep(struct aeEventLoop *eventLoop) { UNUSED(eventLoop); + /* Do NOT add anything above moduleAcquireGIL !!! */ + + /* Aquire the modules GIL so that their threads won't touch anything. */ if (!ProcessingEventsWhileBlocked) { if (moduleCount()) moduleAcquireGIL(); }