Note
Fixed since released on spring-framework 5.3.33 (apparently by this)
Sometimes the SSE message leaks to the body of a regular request. For instance, if I have a heartbeat system that sends a message from time to time to the SSE connections, the message may appear in the response of another unrelated request.
The controller only has two endpoints, one to create an SSE connection and another to send a sample json, plus a scheduled task that runs every .5 seconds to send a heartbeat message to all SSE connections.
The test basically does the following:
- Starts a thread which creates SSE connections that will quickly disconnect
- Starts another thread that runs in parallel with step 1, which executes a regular request with something returning in the body
- Wait for the body of a request made in step 2 contains the message sent to a SseEmitter created in step 1
-
Tested with spring-boot
2.7.18, spring-framework5.3.31and Tomcat embed9.0.83 -
Also tested with spring-boot
3.2.0, spring-framework6.1.1and Tomcat embedded10.1.16and the bug does not reproduce -
I didn't manage to reproduce the bug when no message sent before the
SseEmitterobject is returned to the client, which may indicate that the bug is in Springhowever
-
I also didn't manage to reproduce the bug when using Jetty instead of Tomcat, which may indicate that the bug is in Tomcat
A better way to test that would be to run the application with the same spring version,
changing only the tomcat version, but Spring 2.7 is not compatible with Tomcat 10,
and Spring 3 is not compatible with Tomcat 9