The issue
When connecting to the TOCK backend through an intermediate frontend server, and the connection gets lost, the browser does only one attempt at reconnecting, then gives up:
In comparison, when the browser or the frontend server is offline, or when there is no intermediate frontend server, the connection can be retried several times:
In our case, our frontend server has high availability but our backend servers are susceptible to restarting, so it is quite important that the connection gets retried in those cases too.
The diagnosis
The SSE EventSource comes with a built-in retry mechanism, but it is dependant on the browser. Based on my tests, at least Firefox and Edge seem to attempt a reconnection every few seconds when no connection can be established, but give up immediately when receiving any kind of response (including a 5XX).
Solutions
The simple solution would be to update the onerror event listener on the EventSource such that it automatically reconnects whenever an error of any kind occurs. However, we also need to support the case where the backend does not have SSE enabled. This case could be determined using the status code; however the basic EventSource does not seem to provide any kind of context regarding any error, so we may need to replace it with an alternative implementation.
The issue
When connecting to the TOCK backend through an intermediate frontend server, and the connection gets lost, the browser does only one attempt at reconnecting, then gives up:
In comparison, when the browser or the frontend server is offline, or when there is no intermediate frontend server, the connection can be retried several times:
In our case, our frontend server has high availability but our backend servers are susceptible to restarting, so it is quite important that the connection gets retried in those cases too.
The diagnosis
The SSE
EventSourcecomes with a built-in retry mechanism, but it is dependant on the browser. Based on my tests, at least Firefox and Edge seem to attempt a reconnection every few seconds when no connection can be established, but give up immediately when receiving any kind of response (including a 5XX).Solutions
The simple solution would be to update the
onerrorevent listener on theEventSourcesuch that it automatically reconnects whenever an error of any kind occurs. However, we also need to support the case where the backend does not have SSE enabled. This case could be determined using the status code; however the basicEventSourcedoes not seem to provide any kind of context regarding any error, so we may need to replace it with an alternative implementation.