fix(pglite): resend a request the backend produced no output for

Three times during a scan on a real library, a new pool connection's
first query got no bytes back at all, which the previous commit turned
from a hang into an error. A run always emits at least a completion, so
no output means the packet was not run; the bridge now hands it over
again (twice at most) and logs it.
This commit is contained in:
Deluan 2026-09-04 23:32:29 -04:00
commit f4effde18e

View file

@ -512,6 +512,7 @@ func (pg *PGlite) forwardWire(packet []byte, outFile string) ([][]byte, error) {
_, _ = pg.fnUseWire.Call(ctx, api.EncodeI32(1))
}
var replies [][]byte
resends := 0
for range maxTicks {
producedBefore := pg.collectReply(outFile, &replies)
t0 := time.Now()
@ -544,6 +545,16 @@ func (pg *PGlite) forwardWire(packet []byte, outFile string) ([][]byte, error) {
}
producedAfter := pg.collectReply(outFile, &replies)
if !producedBefore && !producedAfter {
// No output at all means the backend did not run the packet (a run always emits at
// least a completion); seen right after handshakes. Hand it over again, twice at most.
if len(packet) > 0 && len(replies) == 0 && resends < 2 {
resends++
fmt.Fprintf(pg.cfg.Stderr, "# bridge: empty reply to %s; resending (%d)\n", wireTags(packet), resends)
if err := pg.send(packet, strings.TrimSuffix(outFile, ".out")); err != nil {
return nil, err
}
continue
}
break
}
if endsWithReadyForQuery(replies) {