Re: Fix a race condition in ConditionVariableTimedSleep() - Mailing list pgsql-hackers

From Nazir Bilal Yavuz
Subject Re: Fix a race condition in ConditionVariableTimedSleep()
Date
Msg-id CAN55FZ2GHPSAqC3c+tiYwTSyu-nbAsqdTjn_JVQHA9y1wLO=LA@mail.gmail.com
Whole thread Raw
In response to Fix a race condition in ConditionVariableTimedSleep()  (Bertrand Drouvot <bertranddrouvot.pg@gmail.com>)
Responses Re: Fix a race condition in ConditionVariableTimedSleep()
List 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



pgsql-hackers by date:

Previous
From: Mikhail Kharitonov
Date:
Subject: [PATCH] Fix replica identity mismatch for partitioned tables with publish_via_partition_root
Next
From: David Rowley
Date:
Subject: Re: PG 18 release notes draft committed