ragona
ragona

Reputation: 93

Is this the expected SSE EventSource reconnect behavior?

TLDR: Is EventSource supposed to reconnect constantly even when it's already connected?

I've got a simple SSE implementation working, and I'm curious about whether the behavior I'm seeing is expected. Here's the JS:

source = new EventSource("http://localhost:8000/stream")

source.onopen = function(e) {
  console.log(e);
}
source.onmessage = function(e) {
  console.log(e);
}

Here's the behavior I'm seeing: The client successfully connects, and after the amount of time defined in the event stream's reconnection time it reconnects. This is the behavior even if the client is still connected and receiving events from the server.

I was expecting that the reconnection logic would only trigger after a disconnect or error, but it appears to just reconnect constantly. Neither the server nor client appear to have closed the connection prematurely, and perhaps this is working as intended.

Thoughts?

Upvotes: 0

Views: 1409

Answers (1)

ragona
ragona

Reputation: 93

Have confirmed that this is not the intended behavior. This sample SSE implementation from Ismasan appropriately keeps the connection alive.

Upvotes: 1

Related Questions