Skip to content

Commit 1cb4967

Browse files
authored
Merge pull request #10 from CherkashinSergey/fix_segfault
Fix bug related with queries to dead backends
2 parents b7d5f98 + 91e3196 commit 1cb4967

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

pg_query_state.c

+17-5
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,11 @@ pg_query_state(PG_FUNCTION_ARGS)
618618
shm_mq_msg *msg = (shm_mq_msg *) lfirst(i);
619619
proc_state *p_state = (proc_state *) palloc(sizeof(proc_state));
620620

621+
if (msg->result_code != QS_RETURNED)
622+
continue;
623+
624+
AssertState(msg->result_code == QS_RETURNED);
625+
621626
qs_stack = deserialize_stack(msg->stack, msg->stack_depth);
622627

623628
p_state->proc = msg->proc;
@@ -856,7 +861,12 @@ SendBgWorkerPids(void)
856861
msg->number = list_length(all_workers);
857862
i = 0;
858863
foreach(iter, all_workers)
859-
msg->pids[i++] = lfirst_int(iter);
864+
{
865+
pid_t current_pid = lfirst_int(iter);
866+
867+
AssertState(current_pid > 0);
868+
msg->pids[i++] = current_pid;
869+
}
860870

861871
shm_mq_send(mqh, msg_len, msg, false);
862872
}
@@ -894,9 +904,10 @@ GetRemoteBackendWorkers(PGPROC *proc)
894904

895905
for (i = 0; i < msg->number; i++)
896906
{
897-
pid_t pid = msg->pids[i];
898-
PGPROC *proc = BackendPidGetProc(pid);
899-
907+
pid_t pid = msg->pids[i];
908+
PGPROC *proc = BackendPidGetProc(pid);
909+
if (!proc || !proc->pid)
910+
continue;
900911
result = lcons(proc, result);
901912
}
902913

@@ -971,7 +982,8 @@ GetRemoteBackendQueryStates(PGPROC *leader,
971982
foreach(iter, pworkers)
972983
{
973984
PGPROC *proc = (PGPROC *) lfirst(iter);
974-
985+
if (!proc || !proc->pid)
986+
continue;
975987
sig_result = SendProcSignal(proc->pid,
976988
QueryStatePollReason,
977989
proc->backendId);

0 commit comments

Comments
 (0)