Re: Fix a race condition in ConditionVariableTimedSleep()
Nazir Bilal Yavuz <byavuz81@gmail.com>
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Date: 2025-05-05T09:15:39Z
Lists: pgsql-hackers
Hi, Thanks for the report and the patch! On Mon, 5 May 2025 at 10:53, Bertrand Drouvot <bertranddrouvot.pg@gmail.com> wrote: > > The proposed fix attached is done in ConditionVariableTimedSleep() as this is the > place that introduces the race condition. It re-assigns cv_sleep_target to cv > and then ensures that cv_sleep_target accurately describes which condition > variable we’re prepared to wait on. > > Looking forward to your feedback, I am able to reproduce the race condition and confirm that the proposed patch fixes the problem. However AFAIU, the code expects that ConditionVariableCancelSleep() should not be called while waiting for the latch, right? If that is the case, does not the reproducer code violate this? -- Regards, Nazir Bilal Yavuz Microsoft