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.

Server Sent Events delaying 200 response

See original GitHub issue

Describe the bug

I am on 2.6.1.Final. I have an endpoint that is an SSE endpoint. The status code is only returned after the first element is produced.

This was not the case in 1.x and can lead to timeouts on clients.

Expected behavior

I would expect a 200 to be returned immediately (provided everything worked as expected).

Actual behavior

The status code, headers, etc. is not returned until the moment the first item is produced.

How to Reproduce?

getting-started.zip

Output of uname -a or ver

Linux jose-buguroo 5.11.0-41-generic #45-Ubuntu SMP Fri Nov 5 11:37:01 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version “14.0.2” 2020-07-14 OpenJDK Runtime Environment (build 14.0.2+12-46) OpenJDK 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.6.1.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /home/jose/.m2/wrapper/dists/apache-maven-3.6.3-bin/1iopthnavndlasol9gbrbg6bf2/apache-maven-3.6.3 Java version: 14.0.2, vendor: Oracle Corporation, runtime: /home/jose/.sdkman/candidates/java/14.0.2-open Default locale: en_US, platform encoding: UTF-8 OS name: “linux”, version: “5.11.0-41-generic”, arch: “amd64”, family: “unix”

Additional information

From what I see SseUtil.send is producing the response the first time an element is produced. Therefore, until the first element is generated, no call to it happens and no response is flushed. I see this could have to do with PublisherResponseHandler suspending the context. I wonder if an option could be to have that class handle SSE slightly different and generate a status code.

I see that adding:

requestContext.serverResponse().setStatusCode(200)
requestContext.serverResponse().setChunked(true)
requestContext.serverResponse().write(new byte[]{})

to PublisherResponseHandler works as expected (i.e. we get the status code, headers, etc. and then the events get produced as they come). Any reason you can think of not to do that?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:29 (28 by maintainers)

github_iconTop GitHub Comments

2reactions
gsmetcommented, Jan 11, 2022

I’m no SSE expert, just a user, but as a user I would expect the 200 to come right away and then receive the events.

Maybe @cescoffier has an opinion too as he played quite a lot with this.

1reaction
kdubbcommented, Jan 13, 2022

I’m only ever referring to RestEasy server here. By “client” in the above quote I meant an EventSource as defined by the WHATWG Spec.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Sent Events Delay - node.js - Stack Overflow
Setup: I have a nodejs backend trying to send events using SSE to a React App client, while having nginx as a proxy....
Read more >
Server Sent Events - The Modern JavaScript Tutorial
There's a small delay between reconnections, a few seconds by default. The server can set the recommended delay using retry: in response (in ......
Read more >
Browser APIs and Protocols: Server-Sent Events (SSE)
The SSE specification recommends a 2–3 second delay, which is a common default for most browsers, but the server can also set a...
Read more >
16. Server-Sent Events (SSE) - High Performance Browser ...
By default, if the connection is dropped, then the browser will automatically reestablish the connection. The SSE specification recommends a 2–3 second delay, ......
Read more >
Server-Sent Events - W3C
HTTP 200 OK responses with a Content-Type header specifying the type ... after a delay equal to the reconnection time of the event...
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