Re: BackgroundPsql swallowing errors on windows
Noah Misch <noah@leadboat.com>
From: Noah Misch <noah@leadboat.com>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers@postgresql.org
Date: 2025-02-16T17:39:43Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
tests: BackgroundPsql: Fix potential for lost errors on windows
- bb2bf22761e1 13.21 landed
- c21ebcca7965 14.18 landed
- 70b650d18553 15.13 landed
- 4c9397c374d9 16.9 landed
- f61769adaa62 17.5 landed
- 8b886a4e3488 18.0 landed
-
Improve handling of empty query results in BackgroundPsql::query()
- 70291a3c66ec 18.0 cited
-
Extend Cluster.pm's background_psql() to be able to start asynchronously
- ba08edb06545 18.0 cited
On Thu, Feb 13, 2025 at 12:39:04PM -0500, Andres Freund wrote: > My understanding is that IPC::Run uses a proxy process on windows to execute > subprocesses and then communicates with that over TCP (or something along > those lines). Right. > I suspect what's happening is that the communication with the > external process allows for reordering between stdout/stderr. > > And indeed, changing BackgroundPsql::query() to emit the banner on both stdout > and stderr and waiting on both seems to fix the issue. That makes sense. I wondered how one might fix IPC::Run to preserve the relative timing of stdout and stderr, not perturbing the timing the way that disrupted your test run. I can think of two strategies: - Remove the proxy. - Make pipe data visible to Perl variables only when at least one of the proxy<-program_under_test pipes had no data ready to read. In other words, if both pipes have data ready, make all that data visible to Perl code simultaneously. (When both the stdout pipe and the stderr pipe have data ready, one can't determine data arrival order.) Is there a possibly-less-invasive change that might work? > The banner being the same between queries made it hard to understand if a > banner that appeared in the output was from the current query or a past > query. Therefore I added a counter to it. Sounds good. > For debugging I added a "note" that shows stdout/stderr after executing the > query, I think it may be worth keeping that, but I'm not sure. It should be okay to keep. We're not likely to funnel huge amounts of data through BackgroundPsql. If we ever do that, we could just skip the "note" for payloads larger than some threshold. v2 of the patch looks fine.