`Effect.request` batch pool retains completed request context through shared closures
メンテナーはふだん 1 日以内に返信
関連するプルリクエストがすでにマージされています。
- #10125 @pujitha24 による — マージ済み
評価
- 難易度
- 4/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- node.js, typescript
- 領域
- backend, performance
調査の方向性
Start by comparing the published 4.1.0 implementation of Effect.request and its batch pool with the 4.0.2 change that extracted batch construction into a module-level makeBatch function. Run the supplied node --expose-gc repro.mjs reproduction before and after any change; done means the completed request no longer retains its originating context, while preserving batch cleanup behavior.
索引モデルが issue の本文から書いたものです。
説明
What version of Effect is running?
4.1.0. Also reproduced with 4.0.6.
What steps can reproduce the bug?
Install Effect:
npm install [email protected]
Save the following as repro.mjs, then run node --expose-gc repro.mjs:
import { AsyncLocalStorage } from 'node:async_hooks';
import { Effect, Exit, Request, RequestResolver } from 'effect';
class ExampleRequest extends Request.Class {}
const storage = new AsyncLocalStorage();
const resolver = RequestResolver.make((entries) =>
Effect.sync(() => {
for (const entry of entries) {
entry.completeUnsafe(Exit.succeed('done'));
}
}),
);
let reference;
await storage.run({ data: new Array(100_000).fill('example') }, async () => {
reference = new WeakRef(storage.getStore());
await Effect.runPromise(
Effect.scoped(
Effect.gen(function* () {
const signal = yield* Effect.abortSignal;
return yield* Effect.request(
new ExampleRequest({ signal }),
resolver,
);
}),
),
);
});
for (let i = 0; i < 5; i++) {
await new Promise(setImmediate);
global.gc();
}
console.log({ contextRetained: !!reference.deref() });
The request completes successfully and the scope closes, but the asynchronous context remains reachable after garbage collection. This reproduction does not perform network I/O.
What is the expected behavior?
{ contextRetained: false }
The completed request should not keep its originating asynchronous context alive through the reusable batch pool.
What do you see instead?
{ contextRetained: true }
Observed in five separate processes with Effect 4.1.0 and five with 4.0.6.
Additional information
Environment:
- Node.js: v24.22.1
- V8: 13.6.233.17-node.58
- OS/architecture: macOS arm64
Investigation of Effect 4.0.2 identified this heap retaining path:
module-level batchPool
→ batch.run
→ onExit callback
→ shared addEntry lexical context
→ completed request entry
→ request.signal
→ signal.reason / asynchronous stack
→ AsyncContextFrame
→ AsyncLocalStorage store
The suspected cause is V8 sharing the enclosing lexical context between the persistent batch callbacks and request-specific callbacks created inside addEntry. Clearing the batch's explicit fields does not remove this closure reference.
Extracting batch construction into a separate module-level makeBatch function in 4.0.2, while preserving its existing cleanup logic, changed this reproduction to contextRetained: false in five separate processes.
The published 4.1.0 implementation still creates these batch callbacks inside addEntry, and the reproduction above still reports retention.
This is retention through a bounded reusable pool, not a claim of unlimited pool growth. The proposed extraction was tested against 4.0.2; it has not yet been applied and validated against 4.1.0.
- 主要言語
- TypeScript
- スター
- 16.7k
- フォーク
- 808
- 平均マージ
- 10時間 17分
- マージ済み PR(30日)
- 850
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Effect-TS/effect のほかの issue
-
[email protected]: crypto declarations require a global CryptoKey type, breaking Node-only type-checks with @types/node 22 and 24対応中かも @effect-bot が今日担当しました。 オープンbug
Effect-TS/effect#10196 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
OpenApi.fromApi (4.1.0) emits duplicate component schemas with a _1 suffix when the encoded side differs再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 47/100
メンテナーはふだん 1 日以内に返信
-
`fromJsonSchemaDocument`: import open `patternProperties`対応中かも @effect-bot が 2 日前に担当しました。 オープン
Effect-TS/effect#10048 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
Effect-TS/effect の issue をすべて見る
似ている issue
-
area: triage theme: undefined
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
jhipster/generator-jhipster#35895 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
paperclipai/paperclip#18396 ·
メンテナーはふだん 1 日以内に返信
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
lingdojo/kana-dojo#33380 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
-
chore other
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
alastair-smith/card-games#342 ·
メンテナーはふだん 1 日以内に返信