From 51b390ef791114bd971a3fc2a9b650d351325b3c Mon Sep 17 00:00:00 2001 From: Tanzeel Khan <140405735+tanscorpio7@users.noreply.github.com> Date: Mon, 30 Dec 2024 23:21:21 +0530 Subject: [PATCH] Fix sys.dm_exec_sessions having rows for backends which are already terminated (#3329) We initialize and keep a local status array which has the entries for all TDS connections but we did not reset these entries during connection abort or shmem exit of the backend, which means future read of this local status array will see these entries as valid. As a fix, mark the status entry as invalid during proc/shmem exit Task: [BABEL-5414] Signed-off-by: Tanzeel Khan tzlkhan@amazon.com --- contrib/babelfishpg_tds/src/backend/tds/tds.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/contrib/babelfishpg_tds/src/backend/tds/tds.c b/contrib/babelfishpg_tds/src/backend/tds/tds.c index 88cf7195d1..3bbe8f70e8 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tds.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tds.c @@ -143,7 +143,7 @@ typedef struct LocalTdsStatus } LocalTdsStatus; static TdsStatus *TdsStatusArray = NULL; -static TdsStatus *MyTdsStatusEntry; +static TdsStatus *MyTdsStatusEntry = NULL; static LocalTdsStatus *localTdsStatusTable = NULL; uint32_t MyTdsClientVersion = 0; @@ -434,9 +434,17 @@ tds_stats_shmem_shutdown(int code, Datum arg) return; /* Safety check ... shouldn't get here unless shmem is set up. */ - if (TdsStatusArray == NULL) + if (TdsStatusArray == NULL || MyTdsStatusEntry == NULL) return; + PGSTAT_BEGIN_WRITE_ACTIVITY(MyTdsStatusEntry); + + MyTdsStatusEntry->st_procpid = 0; /* mark invalid */ + + PGSTAT_END_WRITE_ACTIVITY(MyTdsStatusEntry); + + MyTdsStatusEntry = NULL; + return; }