EventSource
                                
                                
                                
                                    EventSource copied to clipboard
                            
                            
                            
                        No activity within 45000 milliseconds. Reconnecting.
@BishoyBishai can you please explain more about this issue?
We are also seeing same issue in our application where client is continuously complaining No activity within 45000 milliseconds. Reconnecting. but never gets a valid connection. We are sending a heartbeat every 15 seconds to keep the connection alive.
Is it the same behavior that you are experiencing?
I observe the same behaviour. The heartbeat is sent every 15 seconds,  but after about 5 minutes I get the No activity within 45000 milliseconds. Reconnecting. issue. Everything seems to break after this point. SSE requests are repeatedly sent to the server in a 1s frequency. The request's response is 200, however, the event source keeps trying to reconnect (onError behaviour). No errors are shown in the console...
@BishoyBishai , @akaskj , @tiimoS -
I also have this problem. Can we possibly pool knowledge to see if there are any similarities? When I deploy my server everything works great about 90% of the time. However, after some things are changed by Azure (audit policy changes) I seem to have this issue until I restart or redeploy the server.
However, if I manually create SSE messages to the client with actual data all connections stay open. So, it may may be that the small heartbeat messages are being ignored or something else is happening. My message contains a single word 'Heartbeat' in the message.
I may try enlarging that or changing some things around.
What kind of heartbeat do you send?
Maybe it could help if you sent specific type of events and listened to them through addEventLister("type", callback) instead of listening for the generic "message" type. This worked for me at least. I am using Mercure to send messages to the clients.
Here's how I resolved this issue on Spring Boot:
Keep on sending a 'loading message' from your backend server under 45 seconds so that the event channel remains open until real data is fetched.
 long delay;
  @Autowired
  SSEKeepAliveService(@Value("${kraken.sse.keep-alive:#{environment.KRAKEN_SSE_KEEP_ALIVE_DELAY ?: 15}}") final Long delay) {
    this.delay = delay;
  }
  @Override
  public <T> Flux<ServerSentEvent<T>> wrap(Flux<T> flux) {
    return Flux.merge(flux.map(t -> ServerSentEvent.builder(t).build()), Flux.interval(Duration.ofSeconds(this.delay)).map(aLong -> ServerSentEvent.<T>builder().comment("keep alive").build()));
  }
I am sending a loading message after every 15 seconds.
Have a look at this link for reference: https://octoperf.com/blog/2019/10/09/kraken-server-sent-events-reactive/#sse-and-spring-webflux
Hi!I ran into the same problem. Here's how I resolved this issue in the following article #193
Hi Team,
I am also facing the same issue. i can't use this package for SSE in angular application

@udhayaas97 i switched to use https://www.npmjs.com/package/eventsource instead
@cwirz , Thank you for your reply. There I have raised three issues.
- https://github.com/EventSource/eventsource/issues/234
 - https://github.com/EventSource/eventsource/issues/235
 - https://github.com/EventSource/eventsource/issues/236
 
Is there any working example for Angular?
@udhayaas97 Did you find out any solution to your porblem? I am running into same error.
@sanketkarandikar , I didn't find any solution for this issue. I have been using a diffrent way without using this package.
Hi Team,
I am also facing the same issue. i can't use this package for SSE in angular application
I using EventSourcePolyfill and I managed to extend the time from 45000 milliseconds to 2 minutes using heartbeatTimeout: 120000,
    const sse = new EventSourcePolyfill(`yourURL`,
                        {
                            headers: {
                                'Content-Type': 'text/event-stream',
                                'Cache-Control': 'no-cache',
                                'Connection': 'keep-alive',
                                'X-Accel-Buffering': 'no',
                                Authorization: `Bearer ${access_token}`,
                            },
                            heartbeatTimeout: 120000,
                            withCredentials: true,
                        });
        
                            sse.onmessage = (e) => {
                                console.log(e);
                            }
                            sse.onerror = (event) => {
                                console.log(event);
                                sse.close();
                            }
                                    
                                    
                                    
                                
@polixisNG Did that solve the No activity within 45000 milliseconds issue for you?
@jbouhier unfortunately it doesn't solve the issue, I just tested it
@serkyron what is the issue? Do you see it always? or sometimes? Do you send some message every 45 milliseconds?
@serkyron Did you try with 2 minutes timeout ?
@jbouhier Yes, I tried 2 minutes timeout. Same result
@Yaffle My situation is a bit different. I'm not sending heartbeat, but in my case it's not expected. I use Mercure Hub to deliver updates from Symfony backend. So I'm subscribing to a SSE endpoint, and obviously there is no guarantee there will be an update to push every 45 or N seconds.
I can of course set up a cron process sending heartbeat but that sounds like a work around, which I wouldn't like to do. Is there an option to prevent event listener from expecting heartbeat?
@serkyron you could pass heartbeatTimeout option with a big value
@Yaffle My situation is a bit different. I'm not sending heartbeat, but in my case it's not expected. I use Mercure Hub to deliver updates from Symfony backend. So I'm subscribing to a SSE endpoint, and obviously there is no guarantee there will be an update to push every 45 or N seconds.
I can of course set up a cron process sending heartbeat but that sounds like a work around, which I wouldn't like to do. Is there an option to prevent event listener from expecting heartbeat?
@serkyron Mercure automatically sends heartbeat messages, so there is no need to set up a dedicated CRON job. You could consider reducing the default value from 40s seconds to something lower.
Whether to consider a compromise: The server sends an invalid message every less than 45000ms to maintain the connection.
Anyone have an actual solution to this?