Re: timeout value overflow in wait for lsn

Поиск
Список
Период
Сортировка
Искать

Re: timeout value overflow in wait for lsn

От:
"cca5507" <cca5507@qq.com>
Дата:
Вложения:
> We have a loop in the wait infra, which means that the waiter could
> fall asleep several times. Each time takes a INT_MAX maximumly, added
> up toward a value larger than INT_MAX. That is why I was wondering
> whether the bug itself warrants a truncation from 64 to 32. If there
> are user needs like absurdly long timeouts, then we better satisfy
> them and there're ways to do so. But in my poor imagination, waiting
> greater than 25 days seems unlikely in reality. So I voted for the
> limitation of the range.
> 
> > And I think it's ok to use int64
> > as the argument in WaitForLSN() because convert int32 to int64 is always
> > safe.
> 
> Yeah, it is safe only if we handle the checking/rejection properly.
> The wait for infra is also used by repack, which uses timeout as zero
> for an indefinite wait and 100 milliseconds for a finite wait. So it
> is not vulnerable to edge cases like this. But the infra could have
> more potential callers in the future, we better not let them bother
> the extra safety if we can deal with it easily. Sorry if this seems
> nitpicking to you.

Make sense to me. The v2 patch forgets to update the type of the timeout
variable in repack worker, fixed in v3.

--
Regards,
ChangAo Chen

Re: timeout value overflow in wait for lsn

От:
Xuneng Zhou <xunengzhou@gmail.com>
Дата:
On Thu, Aug 20, 2026 at 2:17 PM cca5507  wrote:
>
> > We have a loop in the wait infra, which means that the waiter could
> > fall asleep several times. Each time takes a INT_MAX maximumly, added
> > up toward a value larger than INT_MAX. That is why I was wondering
> > whether the bug itself warrants a truncation from 64 to 32. If there
> > are user needs like absurdly long timeouts, then we better satisfy
> > them and there're ways to do so. But in my poor imagination, waiting
> > greater than 25 days seems unlikely in reality. So I voted for the
> > limitation of the range.
> >
> > > And I think it's ok to use int64
> > > as the argument in WaitForLSN() because convert int32 to int64 is always
> > > safe.
> >
> > Yeah, it is safe only if we handle the checking/rejection properly.
> > The wait for infra is also used by repack, which uses timeout as zero
> > for an indefinite wait and 100 milliseconds for a finite wait. So it
> > is not vulnerable to edge cases like this. But the infra could have
> > more potential callers in the future, we better not let them bother
> > the extra safety if we can deal with it easily. Sorry if this seems
> > nitpicking to you.
>
> Make sense to me. The v2 patch forgets to update the type of the timeout
> variable in repack worker, fixed in v3.

Thanks. WFM.

-- 
Regards,
Xuneng Zhou
HighGo Software Co., Ltd.


Re: timeout value overflow in wait for lsn

От:
Xuneng Zhou <xunengzhou@gmail.com>
Дата:
Hi Nathan,

On Wed, Aug 26, 2026 at 3:51 AM Nathan Bossart  wrote:
>
> Does this one deserve a mention on the open items wiki [0]?
>
> [0] https://wiki.postgresql.org/wiki/PostgreSQL_19_Open_Items

This seems to be a simple issue for me. I am not sure what qualifies
one to be listed in that wiki. Apart from this, I don't have access to
edit that page. I sent an email to the RMT team but did not get a
reply yet.

-- 
Regards,
Xuneng Zhou
HighGo Software Co., Ltd.


Re: timeout value overflow in wait for lsn

От:
Xuneng Zhou <xunengzhou@gmail.com>
Дата:
Hi Changao, Sawada-san,

On Sat, Aug 29, 2026 at 6:02 PM cca5507  wrote:
>
> > Thank you for updating the patch! Here are review comments:
> >
> > +           if (dval < 0.0)
> > +               ereport(ERROR,
> > +                       errcode(ERRCODE_INVALID_PARAMETER_VALUE),
> > +                       errmsg("timeout cannot be negative"));
> >
> > Let's add parser_errposition() here.
> >
> > Probably we can add the same to other ereport(ERROR) handling a
> > timeout option value.
>
> Fixed.
>
> > ---
> >              /*
> >               * Get rid of any fractional part in the input. This is so we
> >               * don't fail on just-out-of-range values that would round into
> >  -            * range.
> >  +            * range.  Round values in (0, 1) up to 1 to avoid treating them as
> >  +            * zero, which means waiting indefinitely.
> >               */
> >  -           dval = rint(dval);
> >  +           if (dval > 0.0 && dval < 1.0)
> >  +               dval = 1.0;
> >  +           else
> >  +               dval = rint(dval);
> >
> > The first paragraph is for the else branch whereas the second
> > paragraph is for the if branch. I think we can write these comments
> > separately in each branch instead.
>
> Fixed.
>
> > ---
> > The documentation says "The timeout might be given as integer number
> > of milliseconds. Also it might be given as string literal with integer
> > number of milliseconds or a number with unit (see Section 19.1.1).",
> > which seems incorrect to me as we parse the timeout value using
> > parse_real(), clearly accepting real values. Or should we have used
> > parse_int() in the first place?
>
> I think it's ok to use parse_real() here because parse_int() also accepts
> real values.

I think there's still subtlety regarding the use of parse_real() or
parse_int() and how to handle fractional values. I'll reply later for
this.

> > Also, I think it's better to mention the maximum value accepted as a
> > timeout value.
>
> Fixed.

Mentioning the max value in doc seems useful to me, despite no
precedents of timeout have done so even if they share the same
capping.

+          The valid range is from 0 to 2,147,483,647 milliseconds, inclusive.
+          A value of zero means waiting indefinitely.

2,147,483,647 milliseconds seems ok for agents to read but not very
interpretable to humans. I doubt that few people would actually type
it manually. The main use here seems to let users have a vague concept
of the max value, so it might be helpful to convert that value to
something that humans can read like xx days.


> > ---
> > I think it's better to add regression tests for the timeout option.
> > 049_wait_for_lsn.pl would be a good place to have them.
>
> Fixed.
>
> > ---
> > The patch needs to run pgindent.
>
> Fixed.
>
> Please see the v5 patch.
>
> --
> Regards,
> ChangAo Chen



--
Regards,
Xuneng Zhou
HighGo Software Co., Ltd.


FAQ