pg.ddx.io  reorg/pg_repack GitHub issues and pull requests  
help / color / mirror / Atom feed
[reorg/pg_repack] issue #356: simple_prompt() hangs because SIGINT handler was overridden
3+ messages / 2 participants
[nested] [flat]

* [reorg/pg_repack] issue #356: simple_prompt() hangs because SIGINT handler was overridden
@ 2023-06-07 12:29  "za-arthur (@za-arthur)" <noreply+za-arthur@github.com>
  0 siblings, 0 replies; 3+ messages in thread

From: za-arthur (@za-arthur) @ 2023-06-07 12:29 UTC (permalink / raw)
  To: reorg/pg_repack <noreply+reorg-pg_repack@github.com>

pg_repack overrides SIGINT handler:
https://github.com/reorg/pg_repack/blob/81f26d10e5e5b0c3fb7afbd5d91f3a6f3dfafd87/bin/pgut/pgut.c#L16...

Because of this it isn't possible to interrupt password prompt with CTRL+C. You need to interrupt it you need to enter some or empty password.
If you do the following steps then pg_repack crashes:
- Run pg_repack
- Press CTRL+C when pg_repack waits for a password
- Enter any password

```
pg_repack -t repack_table -d postgres -U repack_user
Password:
FATAL: interrupted
[1]    36015 IOT instruction (core dumped)  pg_repack -t repack_table -d postgres -U repack_user
```

^ permalink  raw  [nested|flat] 3+ messages in thread

* Re: [reorg/pg_repack] issue #356: simple_prompt() hangs because SIGINT handler was overridden
@ 2023-06-07 12:29  "za-arthur (@za-arthur)" <noreply+za-arthur@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: za-arthur (@za-arthur) @ 2023-06-07 12:29 UTC (permalink / raw)
  To: reorg/pg_repack <noreply+reorg-pg_repack@github.com>

@za-arthur applied label "bug".

^ permalink  raw  [nested|flat] 3+ messages in thread

* Re: [reorg/pg_repack] issue #356: simple_prompt() hangs because SIGINT handler was overridden
@ 2026-11-16 13:13  "ritojoao (@ritojoao)" <noreply+ritojoao@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ritojoao (@ritojoao) @ 2026-11-16 13:13 UTC (permalink / raw)
  To: reorg/pg_repack <noreply+reorg-pg_repack@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!


^ permalink  raw  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2026-11-16 13:13 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-06-07 12:29 [reorg/pg_repack] issue #356: simple_prompt() hangs because SIGINT handler was overridden "za-arthur (@za-arthur)" <noreply+za-arthur@github.com>
2023-06-07 12:29 ` "za-arthur (@za-arthur)" <noreply+za-arthur@github.com>
2026-11-16 13:13 ` "ritojoao (@ritojoao)" <noreply+ritojoao@github.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox