Skip to content

[Bug] SSE does not always automatically reconnect after a connection loss #178

Description

@Fabilin

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:

browser screenshot

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:

image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions