PgBouncer transaction pooling: `prepare` runs outside the read transaction and can land on another backend

オープン
#53 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@sprihaanand-juspay がすでに取り組んでいます。

2026年11月27日 から。

評価

この issue はまだ評価されていません。

説明

Summary

STREAMGRES_READ_PG_DSN is documented as able to point at PgBouncer in transaction pooling mode (docs/deploy.md), and reads are designed around that: one BEGIN … SET TRANSACTION SNAPSHOT …; SELECT …; COMMIT transaction, so the PgBouncer backend stays assigned through snapshot import and query.

That holds on the fast path, but not on the slow one. When a table has a result type the driver does not already know (driver_knows is false — enums, extension types, hand-declared columns without a type OID), Pool::read resolves the result types with client.prepare(sql) before the transaction is opened:

// src/sync/pg/mod.rs — read()
let statement = if driver_knows {
    None
} else {
    match client.prepare(sql).await {   // <-- outside the transaction
        Ok(statement) => Some(statement),
        ...
    }
};
// then: batch_execute("BEGIN … SET TRANSACTION SNAPSHOT …") + query_raw + COMMIT

Under transaction pooling that prepare is a standalone round trip on a pooled client connection. PgBouncer may assign it a different backend than the one that later runs BEGIN … SET TRANSACTION SNAPSHOT, and a prepared statement is backend-local, so the subsequent query_raw can fail (prepared statement "…" does not exist), or PgBouncer can reject the prepare outright (prepared statements are not supported in transaction pooling mode, depending on version and max_prepared_statements). Either way, the read fails for tables whose types are not in the driver's known-type table — exactly the tables the prepare path exists for.

The driver_knows == true path is unaffected: it streams through query_typed_raw and never prepares.

主要言語
Rust
スター
129
フォーク
7
平均マージ
1日 19時間
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

juspay/streamgres のほかの issue

juspay/streamgres の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。