pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chao Li <li.evan.chao@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Fix bug of clearing of waitStart in ProcWakeup()
Date: Tue, 24 Feb 2026 14:28:15 +0800
Message-ID: <537BD852-EC61-4D25-AB55-BE8BE46D07D7@gmail.com> (raw)

Hi,

I just noticed this while reviewing patch [1]. It looks like this is caused by a simple typo.

In ProcWakeup():
```
PGPROC *
ProcWakeup(PGPROC *proc, ProcWaitStatus waitStatus)
{
	PGPROC	   *retProc;

	/* Proc should be sleeping ... */
	if (proc->links.prev == NULL ||
		proc->links.next == NULL)
		return NULL;
	Assert(proc->waitStatus == PROC_WAIT_STATUS_WAITING);

	/* Save next process before we zap the list link */
	retProc = (PGPROC *) proc->links.next;

	/* Remove process from wait queue */
	SHMQueueDelete(&(proc->links));
	(proc->waitLock->waitProcs.size)--;

	/* Clean up process' state and pass it the ok/fail signal */
	proc->waitLock = NULL;
	proc->waitProcLock = NULL;
	proc->waitStatus = waitStatus;
	pg_atomic_write_u64(&MyProc->waitStart, 0); <== Here, it should operate on proc

	/* And awaken it */
	SetLatch(&proc->procLatch);

	return retProc;
}
```

Since this function is clearly operating on the parameter proc, the only statement that touches MyProc looks suspicious. It should reset proc->waitStart, not MyProc->waitStart.

As written, it will incorrectly clear the caller’s waitStart instead of the awakened backend’s, potentially leaving a stale waitStart value in the target PGPROC.

[1] https://postgr.es/m/CAHGQGwGw4LhNwOGQT3nbw3uWy8gL94_MB4T39Wfr4_Vgopuovg@mail.gmail.com

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/









view thread (10+ messages)  latest in thread

Message-ID: <537BD852-EC61-4D25-AB55-BE8BE46D07D7@gmail.com>
Permalink:  ../537BD852-EC61-4D25-AB55-BE8BE46D07D7@gmail.com/
Also on:    postgresql.org/message-id/537BD852-EC61-4D25-AB55-BE8BE46D07D7@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: li.evan.chao@gmail.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: Fix bug of clearing of waitStart in ProcWakeup()
  In-Reply-To: <537BD852-EC61-4D25-AB55-BE8BE46D07D7@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox