Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

`Effect.request` batch pool retains completed request context through shared closures

クローズ
#10,114 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

関連するプルリクエストがすでにマージされています。

  • #10125 @pujitha24 による — マージ済み

評価

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

調査の方向性

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 の本文から書いたものです。

説明

bug
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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

Effect-TS/effect のほかの issue

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

似ている issue

TypeScript の issue をもっと見る

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

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