According to [Asynchronous Requests :: Spring Framework](https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-ann-async.html) , I wrote a spring boot application to handle server sent events (SSE). Unfortunately, client can't receive message from server instantly, it can receive message until the SSE connection closed (timed out or the backend spring boot application exit). I have posted this problem to [spring-projects/spring-boot: Spring Boot (github.com)](https://github.com/spring-projects/spring-boot/issues/42315) and [Server sent events (SSE) with spring boot have a wrong behavior - Stack Overflow](https://stackoverflow.com/questions/78985741/server-sent-events-sse-with-spring-boot-have-a-wrong-behavior) , but I believe this case should be a bug of spring framework or, at least, the documentation and error detection during compiling process should be enhanced.
To reproduce the problem, simply download the zip file I submitted, use maven to compile the project in "demo" directory and use nginx as a reverse proxy server to handle the project in "nginx" directory. sse.zip
Comment From: bclozel
I don't think this is a bug in Spring, but probably in your JavaScript or your setup. The application is provided as code snippets so I can't reproduce.
This works well with curl so I don't think the problem is on the server side.
$ curl -H "Content-Type: text/plain" --data "message" -vv http://localhost:8080/api/contest/admin/broadcast
* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:8080...
* Connected to localhost (::1) port 8080
> POST /api/contest/admin/broadcast HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.7.1
> Accept: */*
> Content-Type: text/plain
> Content-Length: 7
>
* upload completely sent off: 7 bytes
< HTTP/1.1 200
< Content-Length: 0
< Date: Sun, 15 Sep 2024 08:20:16 GMT
<
* Connection #0 to host localhost left intact
curl --no-buffer -vv http://localhost:8080/api/contest/sse
* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:8080...
* Connected to localhost (::1) port 8080
> GET /api/contest/sse HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.7.1
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 200
< Content-Type: text/event-stream
< Transfer-Encoding: chunked
< Date: Sun, 15 Sep 2024 08:20:06 GMT
<
event:message
data:message
* Connection #0 to host localhost left intact
There is no need to open multiple Spring issues, StackOverflow is the right place for this type of support.