From: ritojoao (@ritojoao) <noreply+ritojoao@github.com>
To: reorg/pg_repack <noreply+reorg-pg_repack@github.com>
Subject: Re: [reorg/pg_repack] issue #356: simple_prompt() hangs because SIGINT handler was overridden
Date: Mon, 16 Nov 2026 13:13:05 +0000
Message-ID: <gh-reorg-pg_repack-356-c6917413467@github.com> (raw)
In-Reply-To: <gh-reorg-pg_repack-356@github.com>
References: <gh-reorg-pg_repack-356@github.com>
Hi, and thank you for pg_repack.
I looked at this one and found the cause. pg_repack installs a SIGINT handler that only sets a flag. While the "Password:" prompt waits for input, Ctrl+C does nothing. If you then type the password, pg_repack connects, sees the flag and stops with "FATAL: interrupted". That path calls abort(), so you also get a core dump.
I wrote a small patch. It uses the default SIGINT action only while the prompt is shown, and restores the previous handler afterwards. It is 12 lines in bin/pgut/pgut.c. Branch: https://github.com/ritojoao/pg_repack/tree/fix-356.
What I tested:
- PostgreSQL 17.12, Linux, gcc 14.2, a user with scram-sha-256 over TCP, driven through a pty.
- Before: Ctrl+C then the right password gives "FATAL: interrupted" and SIGABRT with a core. Ctrl+C then an empty password gives the same. Ctrl+C alone leaves the prompt open.
- After: all three cases end by SIGINT, with no core and no wait for input.
- A normal login still works (exit 0), and a wrong password still gives the same error (exit 255).
- make installcheck gives the same result before and after: 11 of 13 pass. The 2 failures (tablespace, publication) happen without the patch too, in my setup.
What I did not test:
- Other PostgreSQL versions. Only 17 was built, so the code for PG before 14 was not compiled.
- Windows. The change is inside #ifndef WIN32.
- --jobs. By reading the code, the prompt only happens before any connection exists, so no cleanup is skipped.
- The terminal echo after Ctrl+C. bash restores it. I did not check other shells.
- A regression test. It needs a TTY, so I did not add one to installcheck.
If you prefer a softer approach (exit through a clean FATAL, with no core), I can try that. It needs a handler that interrupts the read, so it is more code. Happy to change anything.
Thanks!