From cac5f7d916ba52b60e94385868848223febd8e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=B7=C2=B6=C3=88=C3=B3=C3=94=C3=B3?= Date: Thu, 18 Apr 2024 11:23:16 +0800 Subject: [PATCH] Fix core dump issue by copying data instead of freeing it prematurely in dispatcher - Identified an issue where a block worker, upon completing processing of data, would prematurely free the data. - This led to a situation where the freed data was still being referenced in the dispatcher worker loop, resulting in a core dump. - To address this issue, a change was made to copy the relevant data instead of freeing it, ensuring that the dispatcher worker loop has a valid reference to the data. --- src/backend/access/transam/parallel_replay.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/backend/access/transam/parallel_replay.c b/src/backend/access/transam/parallel_replay.c index e79eb2370d..27989a8923 100644 --- a/src/backend/access/transam/parallel_replay.c +++ b/src/backend/access/transam/parallel_replay.c @@ -5110,7 +5110,13 @@ dispatcherWorkerLoop(void) addDispatchDataToTxn(dispatch_data, true); sync_needed = isSyncAfterDispatchNeeded(reader) ? true : false; - for (worker_list = dispatch_data->worker_list; *worker_list > PR_DISPATCHER_WORKER_IDX; worker_list++) + int copy_worklist_num = dispatch_data->n_involved + 1; + int* copy_worklist = palloc(sizeof(int) * copy_worklist_num); + for (int i = 0; i < copy_worklist_num; i++) + { + copy_worklist[i] = dispatch_data->worker_list[i]; + } + for (worker_list = copy_worklist; *worker_list > PR_DISPATCHER_WORKER_IDX; worker_list++) { #ifdef WAL_DEBUG if (*worker_list == PR_TXN_WORKER_IDX) @@ -5121,6 +5127,7 @@ dispatcherWorkerLoop(void) #endif PR_enqueue(dispatch_data, XLogDispatchData, *worker_list); } + pfree(copy_worklist); if (sync_needed) PR_syncAll(false);