http.Server should lower off, listeners, and newListener for HTTP events

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

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

@espetro がすでに取り組んでいます。

2026年11月3日 から。

  • #2940 @espetro による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
20/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
nodejs, typescript
領域
networking

調査の方向性

Start with the repro program in the issue body and the T3 harness it cites, src/httpResponseErrorGuard.ts (rejectRequestsUntilServing), to see which http.Server calls fail to lower: off, listeners, and on("newListener") for HTTP events. Work already exists in linked pull request #2940, so check that first. Done means the repro compiles and matches Node's listener ordering and identity semantics.

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

説明

Summary

http.Server is a net handle, not %EventEmitter. off(), listeners(), and on("newListener") therefore have no lowering for HTTP events, even though on("request") / on("upgrade") already do.

T3 Code's src/httpResponseErrorGuard.ts (rejectRequestsUntilServing) is the real-world harness: it registers temporary 503 handlers, then uses newListener + listeners().includes() + off() to drop them when the serving handlers attach. Node emits newListener before the add, so the handoff is synchronous.

Expected

This program should compile and match Node:

import * as http from "node:http";

const server = http.createServer();
const rejectRequest = (_req: http.IncomingMessage, res: http.ServerResponse) => {
  res.writeHead(503).end();
};
server.on("request", rejectRequest);
server.on("newListener", function onNewListener(event) {
  if (event === "request") server.off("request", rejectRequest);
  if (!server.listeners("request").includes(rejectRequest)) {
    server.off("newListener", onNewListener);
  }
});
server.on("request", (_req, res) => {
  res.end("ok");
});

newListener fires before the second on("request"), off removes the last matching HTTP listener, and listeners() returns those functions by identity.

Actual (0.4.7)

server.off("request" | "upgrade" | "newListener"), server.listeners(...), and server.on("newListener") are SC1090 / no-lowering. Net-only off("error" | "close" | ...) already works.

Out of scope (fork-side)

res.on("error") on ServerResponse is a different surface. The T3 fork should replace that with abort/writableEnded rather than asking scriptc to lower writable error events in this issue.

Evidence

Plan E3: real src/httpResponseErrorGuard.ts harness failed on newListener, listeners(), off(), res.on("error").

主要言語
TypeScript
スター
6.4k
フォーク
204
平均マージ
9時間 48分
マージ済み PR(30日)
795

環境構築

はじめの一歩

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

vercel-labs/scriptc のほかの issue

vercel-labs/scriptc の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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