From b830cecf971e8c23fc2183a20d6c4b48224ca85a Mon Sep 17 00:00:00 2001 From: Rongsong Shen Date: Fri, 8 May 2026 08:46:27 +0000 Subject: [PATCH] fix: skip BEFORE_EVENT in persist hook functions to prevent crash All three persist hook functions (job/worker/queue) were ignoring the situation argument, so they fired on both BEFORE and AFTER events. BEFORE_EVENT hooks pass different va_list layouts than AFTER_EVENT: - WORKER_JOIN BEFORE: (cluster_t*, char* name, int 0) vs AFTER: (cluster_t*, worker_t*) - JOB_NEW BEFORE: (cluster_t*, xce_job_submit_t*) vs AFTER: (cluster_t*, xlist_t*) Reading the wrong type from va_list caused a dereference crash. Fix: return 0 immediately on HOOK_BEFORE_EVENT in all three hooks. --- src/controller/persist.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/controller/persist.c b/src/controller/persist.c index 85f50615..81c36ff6 100644 --- a/src/controller/persist.c +++ b/src/controller/persist.c @@ -993,7 +993,10 @@ int persist_job_hook_fun(int type, int situation, int detail, void* cls, va_list ap) { (void)type; - (void)situation; + /* Write to WAL only after the state change is complete. + * BEFORE_EVENT has a different va_list layout and must be ignored. */ + if (situation != HOOK_AFTER_EVENT) + return 0; persist_t* p = cls; uint32_t wal_type = detail_to_wal_type(detail); @@ -1065,7 +1068,8 @@ int persist_queue_hook_fun(int type, int situation, int detail, void* cls, va_list ap) { (void)type; - (void)situation; + if (situation != HOOK_AFTER_EVENT) + return 0; persist_t* p = cls; uint32_t wal_type = detail_to_wal_type(detail); @@ -1096,7 +1100,8 @@ int persist_worker_hook_fun(int type, int situation, int detail, void* cls, va_list ap) { (void)type; - (void)situation; + if (situation != HOOK_AFTER_EVENT) + return 0; persist_t* p = cls; uint32_t wal_type = detail_to_wal_type(detail);