Closed skrishnankutty closed 7 years ago
If I understand correctly, a full shutdown of tomcat will trigger the onerror
event in the client.
However, only stopping the server app, but not tomcat, does not trigger the onerror
event in the client.
From the EventSource
's perspective, the client either has an open http connection or it does not. When the server interrupts the http connection, the onerror
event is triggered.
It sounds like stopping the server app doesn't close the http connection, and therefore, onerror
isn't triggered in the client.
EventSource connections are long-lived http connections. It's not uncommon for web servers to not shut down until all HTTP connections have finished. With EventSource connections, this never happens, so the shutdown never completes.
You probably need to explicitly close all open EventSource connections before you shut down. Or figure out a way to make that happen automatically.
In Node.js there is https://github.com/isaacs/server-destroy to solve this problem - I'm not sure what's available for Tomcat.
We are having an issue with the following setup:
We have a server application that uses Spring's implementation of SSE. This app is deployed on a Tomcat 8.5 server, say on http://localhost:8080/myapp. The 'register' method on this app creates the SseEmitter like this:
SseEmitter sseEmitter = new SseEmitter(Long.valueOf(this.TIMEOUT)); SseEventBuilder sseEventBuilder = SseEmitter.event(); sseEventBuilder.reconnectTime(30000); sseEmitter.send(sseEventBuilder);
We have a client application that uses the eventsource-polyfill.js example. the EventSource object is initialized with an endpoint of the server app url and the corresponding open, message and error handlers:
The following test behaves as expected:
currentTarget: EventSource onerror:f() onmessage:ƒ () onopen:ƒ () readyState:0 url:"http://localhost:8080/myapp/register" withCredentials:true proto:EventSource defaultPrevented:false eventPhase:2 isTrusted:true
path:[] returnValue:true srcElement: EventSource {url: "http://localhost:8080/myapp/register", withCredentials: true, readyState: 0, onopen: ƒ, onmessage: ƒ, …} target:EventSource {url: "http://localhost:8080/myapp/register", withCredentials: true, readyState: 0, onopen: ƒ, onmessage: ƒ, …} type:"error"
But in this case we don't get the expected behaviour:
Tested on eventsource-polyfill.js versions: 1.0.4, 0.2.1