Skip to content

Fix bug related with queries to dead backends #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 1, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions pg_query_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,11 @@ pg_query_state(PG_FUNCTION_ARGS)
shm_mq_msg *msg = (shm_mq_msg *) lfirst(i);
proc_state *p_state = (proc_state *) palloc(sizeof(proc_state));

if (msg->result_code != QS_RETURNED)
continue;

AssertState(msg->result_code == QS_RETURNED);

qs_stack = deserialize_stack(msg->stack, msg->stack_depth);

p_state->proc = msg->proc;
Expand Down Expand Up @@ -856,7 +861,12 @@ SendBgWorkerPids(void)
msg->number = list_length(all_workers);
i = 0;
foreach(iter, all_workers)
msg->pids[i++] = lfirst_int(iter);
{
pid_t current_pid = lfirst_int(iter);

AssertState(current_pid > 0);
msg->pids[i++] = current_pid;
}

shm_mq_send(mqh, msg_len, msg, false);
}
Expand Down Expand Up @@ -894,9 +904,10 @@ GetRemoteBackendWorkers(PGPROC *proc)

for (i = 0; i < msg->number; i++)
{
pid_t pid = msg->pids[i];
PGPROC *proc = BackendPidGetProc(pid);

pid_t pid = msg->pids[i];
PGPROC *proc = BackendPidGetProc(pid);
if (!proc || !proc->pid)
continue;
result = lcons(proc, result);
}

Expand Down Expand Up @@ -971,7 +982,7 @@ GetRemoteBackendQueryStates(PGPROC *leader,
foreach(iter, pworkers)
{
PGPROC *proc = (PGPROC *) lfirst(iter);

Assert (proc && proc->pid);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот здесь тоже надо через continue, бекенд может помереть и в этом месте

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет, Assert тут правильнее - мы предполагаем, что proc никогда не будет нулевым. А вот условие !proc->pid лишнее.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А с чего ты взял что он не может быть нулевым?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У вас тут условие есть в GetRemoteBackendWorkers()

if (!proc || !proc->pid)
   continue;

Поэтому видимо не может быть нулевым.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут в смысле proc нулевым не будет в любом случае, но процесс мог умереть (или завершиться) и проверка на pid все равно нужна. По хорошему вообще SHARED лок надо ставить на procArray

sig_result = SendProcSignal(proc->pid,
QueryStatePollReason,
proc->backendId);
Expand Down