Skip to content

Commit

Permalink
Fix sys.dm_exec_sessions having rows for backends which are already t…
Browse files Browse the repository at this point in the history
…erminated (babelfish-for-postgresql#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 [email protected]
  • Loading branch information
tanscorpio7 committed Dec 30, 2024
1 parent 709938a commit 51b390e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions contrib/babelfishpg_tds/src/backend/tds/tds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 51b390e

Please sign in to comment.