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

Abierto
#2,913 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@espetro ya está trabajando en esto.

Desde el 3/11/2026.

  • #2940 de @espetro — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
20/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
nodejs, typescript
Área
networking

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
TypeScript
Estrellas
6.4k
Forks
204
Merge medio
7 h 35 min
PR fusionados (30 d)
873

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de vercel-labs/scriptc

Todos los issues de vercel-labs/scriptc

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.