sql-pg: pool is not closed when the "SELECT 1" readiness probe fails in PgClient.make

クローズ 初心者向け
#8,424 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
postgresql, typescript
領域
database

調査の方向性

packages/sql/pg/src/PgClient.ts の PgClient.make から始め、プールの作成、SELECT 1 の取得、release finalizer を追跡します。readiness probe の失敗経路を確認し、そこで構築されたプールが終了されるようにしつつ、取得に成功した場合の既存のクリーンアップ動作を維持してください。

索引モデルが issue の本文から書いたものです。

説明

3.0

Package

@effect/sql-pg 0.53.0 (the same structure is present in the v4 sources at packages/sql/pg/src/PgClient.ts).

Description

In PgClient.make, the pg.Pool is constructed before the acquisition effect:

const pool = new Pg.Pool({ ... })
pool.on("error", () => {})

yield* Effect.acquireRelease(
  Effect.tryPromise({
    try: () => pool.query("SELECT 1"),
    catch: (cause) => new SqlError({ ... })
  }),
  () => Effect.promise(() => pool.end()).pipe(...)
).pipe(...)

Per Effect.acquireRelease semantics, the release finalizer is registered only after a successful acquire — so when the SELECT 1 readiness probe fails, pool.end() is never called and the already-constructed pool object is orphaned.

Impact

Small in practice (pg pools are lazy — a pool that never acquired a client holds no sockets or timers, so the orphaned object is garbage-collectable), but:

  • callers that retry a failed layer build (e.g. a self-healing wrapper around ManagedRuntime that replaces the runtime after a failed build) accumulate pool instances across attempts,
  • the pool.end() finalizer signals the intent to always release the pool, so a failed probe silently violating that contract is surprising.

Suggested fix

End the pool when the probe fails, e.g.:

Effect.acquireRelease(
  Effect.tryPromise({
    try: () => pool.query("SELECT 1"),
    catch: (cause) => new SqlError({ ... })
  }).pipe(Effect.tapErrorCause(() => Effect.promise(() => pool.end()))),
  () => ...
)

or construct the pool inside the acquire effect.

主要言語
TypeScript
スター
16.7k
フォーク
808
平均マージ
11時間 3分
マージ済み PR(30日)
840

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

Effect-TS/effect のほかの issue

Effect-TS/effect の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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