Re: Use option_parse_int() for pg_createsubscriber --recovery-timeout and pgbench --max-tries

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Raja Sai pranav <rajasaipranav0(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Use option_parse_int() for pg_createsubscriber --recovery-timeout and pgbench --max-tries
Date: 2026-11-27 03:28:52
Message-ID: 5E0CCE28-67F6-4334-939F-AB9FA5037DA7@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Nov 27, 2026, at 02:30, Raja Sai pranav <rajasaipranav0(at)gmail(dot)com> wrote:
>
> Hi,
>
> Two integer options are still read with atoi(), so a non-numeric value
> silently becomes 0:
>
> pg_createsubscriber --recovery-timeout=abc timeout disabled (0 = none)
> pgbench --max-tries=abc unlimited tries
>
> pg_createsubscriber also accepts negative timeouts. The other client
> programs moved to option_parse_int() in 2021 [1]. pg_ctl was left out
> on purpose there (Windows event logging), but pg_createsubscriber did not
> exist yet and uses the common logging.
>
> The attached patch uses option_parse_int() for both, still allowing 0.
> For --max-tries the error for a negative value changes from "invalid
> number of maximum tries" to the usual "must be in range" message.
> Tests are added in https://www.google.com/url?q=http://040_pg_createsubscriber.pl&source=gmail&ust=1795804224713000&sa=E and
> https://www.google.com/url?q=http://002_pgbench_no_server.pl&source=gmail&ust=1795804224713000&sa=E. They fail without the change and pass with it.
>
> [1] https://www.google.com/url?q=https://postgr.es/m/CALj2ACXqdG9WhqVoJ9zYf-iZt7sgK7Szv5USs%3Dhe6NnWQ2ofTA@mail.gmail.com&source=gmail&ust=1795804224713000&sa=E
>
> Regards,
> Sai Pranav
> <v1-0001-Use-option_parse_int-for-two-more-integer-options.patch>

I think the fix is reasonable. In pgbench.c, case 11 (--partitions) already uses option_parse_int(), so switching case 14 (--max-tries) from atoi() to option_parse_int() makes the code more consistent.

I searched for atoi() and found similar uses in pg_ctl and pg_upgrade. As commit 6f164e6d176, which introduced option_parse_int(), intentionally excluded those two programs, I’d leave them untouched.

So, v1 looks good to me.

BTW, while testing this patch, I found that option_parse_int() itself also has a bug. After calling strtoint(), it skips trailing whitespace without first checking parsing error. So if we pass a single space as --max-tries=' ', pgbench treats it as 0, just as it treated “abc” as you reported. But that’s a separate issue, and I’ll start a new thread about it.

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message wenhui qiu 2026-11-27 03:41:22 Re: Simplify the uniqueness proof for self-join elimination
Previous Message Ayush Tiwari 2026-11-27 03:21:17 pg_receivewal doesn't truncate compressed WAL files on restart