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

Đang mở
#2,913 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@espetro đang làm issue này rồi.

Từ ngày 3/11/2026.

  • #2940 của @espetro — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
20/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
nodejs, typescript
Lĩnh vực
networking

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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").

Ngôn ngữ chính
TypeScript
Star
6.5k
Fork
212
Merge trung bình
9 giờ 48 phút
Pull request đã merge (30 ngày)
795

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của vercel-labs/scriptc

Tất cả issue của vercel-labs/scriptc

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.