Skip to content

Combining .trace() and .onAfterHandle() causes odd-numbered SSE events to be skipped, even-numbered events still make it through #1717

@coreh

Description

@coreh

What version of Elysia is running?

1.4.22

What platform is your computer?

Darwin 25.3.0 arm64 arm

What environment are you using

bun 1.3.7

Are you using dynamic mode?

No

What steps can reproduce the bug?

import Elysia, { sse } from "elysia";

new Elysia({ aot: true })
  .trace(() => {})
  .onAfterHandle(() => {})
  .get("/sse", async function* () {
    yield sse({ event: "test", data: "1" });
    yield sse({ event: "test", data: "2" });
    yield sse({ event: "test", data: "3" });
    yield sse({ event: "test", data: "4" });
    yield sse({ event: "test", data: "5" });
    yield sse({ event: "test", data: "6" });
  })
  .listen(3000);

console.log("Server running on http://localhost:3000");
console.log("");
console.log("Test with: curl -N http://localhost:3000/sse");
console.log("");
console.log("Expected: events 1, 2, 3, 4, 5, 6");
console.log("Actual:   events 2, 4, 6 (ODD events are dropped, EVEN make it through)");

What is the expected behavior?

$ curl -N http://localhost:3000/sse

event: test
data: 1

event: test
data: 2

event: test
data: 3

event: test
data: 4

event: test
data: 5

event: test
data: 6

What do you see instead?

$curl -N http://localhost:3000/sse
event: test
data: 2

event: test
data: 4

event: test
data: 6

Additional information

  • Using { aot: false } makes the bug go away.
  • Using either .trace() alone or .onAfterHandle() alone also makes the bug go away

Have you try removing the node_modules and bun.lockb and try again yet?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions