Re: Fix a race condition in ConditionVariableTimedSleep()

From: Nazir Bilal Yavuz <byavuz81(at)gmail(dot)com>
To: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Fix a race condition in ConditionVariableTimedSleep()
Date: 2025-05-05 09:15:39
Message-ID: CAN55FZ2GHPSAqC3c+tiYwTSyu-nbAsqdTjn_JVQHA9y1wLO=LA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Thanks for the report and the patch!

On Mon, 5 May 2025 at 10:53, Bertrand Drouvot
<bertranddrouvot(dot)pg(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2025-05-05 09:42:10 Re: PG 18 release notes draft committed
Previous Message Mikhail Kharitonov 2025-05-05 08:18:18 [PATCH] Fix replica identity mismatch for partitioned tables with publish_via_partition_root