Closed spring-projects-issues closed 6 years ago
Rossen Stoyanchev commented
There was a fix made in 5.0 to correct an issue with the Servlet container and the application, both trying to cleanup and interfering with each other, see #20173. The correct way to do this now is to avoid calling emitter.completeWithError(ex)
for an IOException from a send
. The container will provide an error notification, and Spring MVC will cleanup and invoke the onXxx callbacks.
We do need to improve the documentation on this however, but if you could first please confirm it works for you.
Guido commented
@Rossen
Thanks, it works! It looks a bit strange to have an empty catch block around a send, but it works the way you describe.
Rossen Stoyanchev commented
Okay thanks for confirming. I agree it's a bit strange but we don't have much choice, and have to complete processing from within a Servlet container thread.
Rossen Stoyanchev commented
I've updated the docs and also made an extra change to ignore calls to complete
and completeWithError
from a try-catch after a send failure.
Guido opened SPR-16548 and commented
Problem
When using SseEmitter and closing tabs in the browser, the
onComplete
andonError
callbacks are not called for every subscription.Code to subscribe:
Note that an SSE stream is not supposed to know when it is terminated. Only when a message fails to be sent, can the stream be closed. This is what I tried to do.
See below for the output log. I observe that when a
send
call fails, the SseEmitter is not terminated correctly. In addition, it's not possible to mark it as terminated by hand. ThecompleteWithError
call succeeds in one case and fails in another, but neither call seem to register with theonComplete
oronError
listeners.Is this a bug? What is the proper way to implement an SseEmitter?
Steps to reproduce
localhost:8088
in four tabs, then close the first threeResources
Issue Links:
20173 Handle onError events that are sent by the servlet containers
Referenced from: commits https://github.com/spring-projects/spring-framework/commit/568c93457a8487b34381386f06a55e0f22432e9a, https://github.com/spring-projects/spring-framework/commit/e20652009dca44363e7296c7bf7510def391885f