From 2d924045223a9f2396b6a08a939b66e2fe5c5d65 Mon Sep 17 00:00:00 2001 From: ranshid <88133677+ranshid@users.noreply.github.com> Date: Thu, 12 Dec 2024 23:52:58 +0200 Subject: [PATCH] Avoid defragging scripts during EVAL command execution (#1414) This can happen when scripts are running for long period of time and the server attempts to defrag it in the whileBlockedCron. Signed-off-by: Ran Shidlansik --- src/defrag.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/defrag.c b/src/defrag.c index 2fa067f0dc..be7ff07510 100644 --- a/src/defrag.c +++ b/src/defrag.c @@ -34,6 +34,7 @@ */ #include "server.h" +#include "script.h" #include #ifdef HAVE_DEFRAG @@ -1050,6 +1051,9 @@ static doneStatus defragLuaScripts(monotime endtime, void *target, void *privdat UNUSED(target); UNUSED(privdata); if (endtime == 0) return DEFRAG_NOT_DONE; // required initialization + /* In case we are in the process of eval some script we do not want to replace the script being run + * so we just bail out without really defragging here. */ + if (scriptIsRunning()) return DEFRAG_DONE; activeDefragSdsDict(evalScriptsDict(), DEFRAG_SDS_DICT_VAL_LUA_SCRIPT); return DEFRAG_DONE; }