Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] request.signal.onabort never getting fired #10

Open
FluentCoding opened this issue Apr 2, 2024 · 2 comments
Open

[Bug] request.signal.onabort never getting fired #10

FluentCoding opened this issue Apr 2, 2024 · 2 comments

Comments

@FluentCoding
Copy link

Unfortunately, adding an onabort-handler for my SSE-endpoints has only been possible with a workaround which you can see in this minimum reproducible example.

Creating an interval which prevents the request from getting garbage collected makes the onabort work properly. Stream.close() also doesn't call onabort (which makes sense but isn't really practical if you just want to handle connection loss, no matter if the client aborted it or the server), it would be nice if the Stream-API could get extended to allow developers to handle disconnects in an intuitive way.

import { Elysia } from "elysia";
import { Stream } from "@elysiajs/stream";

// [1] => Uncommenting this makes onabort work properly (page close/client-side connection loss calls onabort)
// [2] => stream.close() doesn't trigger onabort as well
// Running the code like this leads to "connection closed" never getting logged even if it should happen
new Elysia()
  .get("/", ({ request }) => {
    request.signal.onabort = () => {
      console.log("connection closed");
      // [1]
      // clearInterval(_);
    };
    // [1]
    // const _ = setInterval(() => request.signal.aborted, Math.pow(2, 31) - 1);
    return new Stream(async (stream) => {
      stream.send("test");
      // [2]
      // stream.close();
    });
  })
  .listen(3000);
@FluentCoding FluentCoding changed the title [Bug] request.signal.onabort [Bug] request.signal.onabort never getting fired Apr 2, 2024
@bogeychan
Copy link

Blocked by: oven-sh/bun#4517

@Jarred-Sumner
Copy link

This will be fixed in Bun v1.1.27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants