question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SSE connection closes immediately with Javalin 4.5.0

See original GitHub issue

Actual behavior (the bug) When upgrading from Javalin 4.4.0 to 4.5.0, SSE event streams stopped working. Rather than holding the stream open so events can be delivered asynchronously, the response stream is closed too soon.

Expected behavior Response stream remains open and async events delivered when published to the SseClient.

To Reproduce

Run:

  public static void main(String[] args) {
    final Javalin javalin = Javalin.create();
    javalin.get("/sse", new SseHandler(client -> {
      client.sendEvent("Sync Event");
      new Thread(() -> {
        while (true) {
          client.sendEvent("Async event");
          LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(5));
        }
      }).start();
    }));
    javalin.start(8080);
  }

And then try to subscribe to the events:

curl -H 'Accept: text/event-stream' http://localhost:8080/sse

The sync event is always delivered and sometimes the first async event, but it doesn’t hold the connection open for later async events.

Additional context The actual application code is from Teku: https://github.com/ConsenSys/teku/blob/38a60ea76e14c240cbcecaccab1a4c4f8734b056/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/events/GetEvents.java#L52

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ajsuttoncommented, May 4, 2022

I get the same issue with .sse. We use .get so we can get the openapi annotations to be picked up as well.

0reactions
tipsycommented, May 5, 2022

@ajsutton this should be fixed now !

Read more comments on GitHub >

github_iconTop Results From Across the Web

News - Javalin - A lightweight Java and Kotlin web framework
The closing of SSE connections is now more consistent, and reloading data in ... Javalin 4.5.0 - Complete rework of async handling and...
Read more >
SSE and WS · Issue #1076 - GitHub
However, I need to send two messages to the SseClient that it gets called. I know you cannot handle the Close-Event instantly when...
Read more >
Javalin - javalin 5.2.0 javadoc - javadoc.io
Synchronously stops the application instance. Recommended to use close instead with Java's try-with-resources or Kotlin's use . This differs from close by ...
Read more >
SSE connection got closed by browser after receiving first data
I wrote a spring sse application but after receiving the first data from server, the sse emitter connection gets closed.
Read more >
washington interscholastic activities association - WIAA
Fraudulence or misconduct in connection with placement examinations; ... 4.5.0. CLASSIFICATIONS FOR SCHOOLS IN MULTIPLE HIGH SCHOOL ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found