pg.ddx.io  pgbouncer/pgbouncer GitHub issues and pull requests  
help / color / mirror / Atom feed
From: eulerto (@eulerto) <noreply+eulerto@github.com>
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
Subject: Re: [pgbouncer/pgbouncer] PR #1667: test: fail tests when PgBouncer exits with an unexpected code
Date: Sat, 24 Oct 2026 02:18:34 +0000
Message-ID: <gh-pgbouncer-pgbouncer-1667-c6378664009@github.com> (raw)
In-Reply-To: <gh-pgbouncer-pgbouncer-1667@github.com>
References: <gh-pgbouncer-pgbouncer-1667@github.com>

The CI failure is not a PgBouncer bug and not a real crash. It is a false positive in the test harness introduced by the current commit in this branch.

The `test_shutdown_wait_for_servers` and `test_shutdown_wait_for_clients` are the only tests where PgBouncer exits on its own (`SHUTDOWN WAIT_FOR_SERVERS` and `SHUTDOWN WAIT_FOR_CLIENTS`). In these cases, PgBouncer exits cleanly (`exit(0)`) once connections drain. The CI logs confirm a clean shutdown.

I cannot reproduce using Python 3.11 but if I use the same Python version (3.12) as CI, both tests reproduces the identical failure:

```
ERROR at teardown of test_shutdown_wait_for_servers
E   RuntimeError: PgBouncer exited with unexpected exit code 255
WARNING  asyncio:unix_events.py:960 child process pid 1543700 exit status already read: will report returncode 255
```

AFAICS The `PidfdChildWatcher` default on Python 3.12+ then cannot read the status in `wait()` and fabricates return code 255 ("exit status already read"), which the new check flags as a crash. This is why those two tests fail on CI (Python 3.12) but not on 3.11, whose `ThreadedChildWatcher` reaps in a loop-independent thread.

One possible fix is if it forces `ThreadedChildWatcher` in the test harness. It reaps in a loop-independent thread and reports the true exit code, so clean shutdowns read 0 and a genuine TSan race still reads 66. The problem is `get_child_watcher` and `set_child_watcher` (functions used to accomplish the goal) are deprecated in Python 3.12 and removed in Python 3.14.

I checked what the test harness relies on from the asyncio subprocess. It seems nothing actually uses the asyncio-ness of that process. Every `self.aprocess` reference: start() (creates it), running() (reads return code), wait_for_exit() (communicate() + wait()), stop() (terminate() -- Windows), send_signal(). There is no async stdout and/or stderr streaming. The `create_subprocess_exec` (utils.py) doesn't even pass PIPE (logs) so communicate() is a no-op. The conclusion is that the process is launched with `await` purely because `start()` happens to be async def. Am I missing something?

We are already using a plain `subprocess.Popen` on Windows. It reaps through `os.waitpid` inside subprocess, independent of any loop, watcher or Python version. Its `.wait()` returns the real exit code. Besides that, we gain in simplification since `self.aprocess` is gone.

The next commit implements `subprocess.Popen` on all platforms instead of an asyncio subprocess on Linux.

view thread (5+ messages)  latest in thread

Message-ID: <gh-pgbouncer-pgbouncer-1667-c6378664009@github.com>
Permalink:  ../gh-pgbouncer-pgbouncer-1667-c6378664009@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