SqlClient: a fiber forked inside a transaction keeps using its connection after the transaction ends
メンテナーはふだん 1 日以内に返信
@effect-bot がすでに取り組んでいます。
2026年11月6日 から。
評価
この issue はまだ評価されていません。
説明
What version of Effect is running?
effect 4.1.2, @effect/sql-sqlite-bun 4.1.2, Bun 1.4.2
What steps can reproduce the bug?
A fiber forked inside withTransaction outlives it. Its context still holds the TransactionConnection, so its
statements go straight to that connection, without the client's lock. Here its plain INSERT runs inside another
fiber's transaction, which then rolls back: the INSERT reported success and the row is gone.
import { SqliteClient } from "@effect/sql-sqlite-bun"
import * as Deferred from "effect/Deferred"
import * as Effect from "effect/Effect"
import * as Fiber from "effect/Fiber"
import { SqlClient } from "effect/sql"
const program = Effect.gen(function*() {
const sql = yield* SqlClient.SqlClient
yield* sql`CREATE TABLE t (who TEXT)`
const go = yield* Deferred.make<void>()
const done = yield* Deferred.make<void>()
// Forked inside a transaction, runs after it has committed.
const stale = yield* sql.withTransaction(
Effect.forkChild(Effect.gen(function*() {
yield* Deferred.await(go)
yield* sql`INSERT INTO t VALUES ('stale fiber')`
yield* Deferred.succeed(done, undefined)
}))
)
const other = yield* Effect.forkChild(Effect.ignore(sql.withTransaction(Effect.gen(function*() {
yield* sql`INSERT INTO t VALUES ('other transaction')`
yield* Deferred.succeed(go, undefined)
yield* Deferred.await(done)
return yield* Effect.fail("rollback")
}))))
yield* Fiber.join(stale)
yield* Fiber.join(other)
console.log(yield* sql`SELECT who FROM t`)
})
Effect.runPromise(program.pipe(Effect.scoped, Effect.provide(SqliteClient.layer({ filename: ":memory:" }))))
What is the expected behavior?
The stale fiber's statement fails, as a statement on a released pin does in @effect/sql-pg since #9089, or it
takes the connection through the client's lock like any other statement. Either way, [ { who: 'stale fiber' } ]
or an error, never a lost row.
What do you see instead?
[]
The INSERT succeeded and was rolled back with the other fiber's transaction. A nested withTransaction in such
a fiber does the same with a SAVEPOINT: SQLite starts a transaction for it outside the lock, and the next
withTransaction to take the lock fails with cannot start a transaction within a transaction.
Additional information
getConnection and makeWithTransaction in SqlClient.ts take the connection from the TransactionConnection
found in the context, with no check that its transaction is still open. #9084 was the same situation on sql-pg,
fixed in the driver by marking a released pin. The SQLite clients share one connection and have nothing to mark,
so the check would have to live where the connection is taken from the context, as the one afterCommit already
does ("the transaction has already ended").
We hit this in a runtime on Effect Cluster, where a handler forks long-lived fibers inside WithTransaction, and
now fork with Effect.updateContext(effect, Context.omit(sql.transactionService)).
- 主要言語
- TypeScript
- スター
- 16.7k
- フォーク
- 808
- 平均マージ
- 12時間 16分
- マージ済み PR(30日)
- 809
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Effect-TS/effect のほかの issue
-
McpServer.layerHttp: optional legacy GET SSE for idle list-change notifications対応中かも @effect-bot が 1 日前に担当しました。 オープン
Effect-TS/effect#10436 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
CLI completions stop offering repeatable flags after their first use対応中かも @effect-bot が 1 日前に担当しました。 オープン
Effect-TS/effect#10427 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
sql-pg: pgvector columns fail with "Invalid UTF-8 in text value"対応中かも @effect-bot が 2 日前に担当しました。 オープンbug
Effect-TS/effect#10420 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
cli: completions break for subcommand names with `:`対応中かも @effect-bot が 2 日前に担当しました。 オープン
Effect-TS/effect#10416 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
McpServer.layerStdio: native EOF cancellation policy for active tool handlers対応中かも @effect-bot が 2 日前に担当しました。 オープン
Effect-TS/effect#10412 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
Effect-TS/effect の issue をすべて見る
似ている issue
-
area:cards enhancement ready-for-agent
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
fil-donadoni/tolaria#8883 ·
メンテナーはふだん 1 日以内に返信
-
xsd:integer cast from a string rejects negative numbers, a leading + and surrounding whitespaceオープンbug 🐛
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
comunica/comunica#1960 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Waiting for: Product Owner
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
getsentry/sentry-javascript#26203 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
bytedance/flowgram.ai#1235 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
devswha/herdr-web-ui#3325 ·