Skip to content

node:http's doesn't trigger 'close' events when the client disconnects. #29799

Open
@sigmaxipi

Description

@sigmaxipi

Version: Deno 2.3.6

The code below works on node (after changing the import), but not on Deno. The req.socket.on("close",... never gets called on Deno so systems that use SSEs or require the client to initiate the disconnect will leak. Using the debugger shows that req.socket.#request.signal does exist, but req.socket.signal is undefined. I guess this means kBindToAbortSignal was never called.

// deno --allow-net sse.js 
import http from "node:http";

// node sse.js
//import http from "http";

const server = http.createServer((req, res) => {
  res.writeHead(200,);

  // On connect.
  res.write(`Client connected!\n\n`);
  console.log(`Client connected!`);

  const interval = setInterval(() => {
    console.log(req.socket); // _events are properly bound for FakeSocket
    console.log(req.signal); // undefined
    console.log(req.socket.signal); // undefined
    debugger;
    
    res.write(`${new Date().toISOString()}\n`);
    console.log(`${new Date().toISOString()}`);
  }, 1000);
  
  // On close. THIS DOESN"T GET CALLED ON DENO.
  req.socket.on("close", () => {
    console.log("Client disconnected from SSE stream.");
    clearInterval(interval);
  });
});

const port = 3141;
server.listen(port, () => console.log(`Server is running on http://localhost:${port}`));

Activity

added
bugSomething isn't working correctly
needs investigationrequires further investigation before determining if it is an issue or not
on Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working correctlyneeds investigationrequires further investigation before determining if it is an issue or notnode compatnode:httpIssues with `node:http` module - to be fixed with a rewrite

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @marvinhagemeister@sigmaxipi@bartlomieju

        Issue actions

          node:http's doesn't trigger 'close' events when the client disconnects. · Issue #29799 · denoland/deno