EventSource icon indicating copy to clipboard operation
EventSource copied to clipboard

No activity within 45000 milliseconds. Reconnecting.

Open BishoyBishai opened this issue 5 years ago • 23 comments

BishoyBishai avatar Jan 24 '20 12:01 BishoyBishai

@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?

akaskj avatar Jan 30 '20 17:01 akaskj

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...

tiimoS avatar Feb 26 '20 12:02 tiimoS

@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?

henry-chris avatar Jun 19 '20 16:06 henry-chris

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.

Vaggal avatar Feb 16 '21 10:02 Vaggal

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

faizansalamat avatar Mar 19 '21 09:03 faizansalamat

Hi!I ran into the same problem. Here's how I resolved this issue in the following article #193

MrJimmyYi avatar Sep 24 '21 07:09 MrJimmyYi

Hi Team,

I am also facing the same issue. i can't use this package for SSE in angular application image

udhayakumarcp avatar Jan 05 '22 12:01 udhayakumarcp

@udhayaas97 i switched to use https://www.npmjs.com/package/eventsource instead

cwirz avatar Jan 12 '22 10:01 cwirz

@cwirz , Thank you for your reply. There I have raised three issues.

  1. https://github.com/EventSource/eventsource/issues/234
  2. https://github.com/EventSource/eventsource/issues/235
  3. https://github.com/EventSource/eventsource/issues/236

Is there any working example for Angular?

udhayakumarcp avatar Jan 12 '22 15:01 udhayakumarcp

@udhayaas97 Did you find out any solution to your porblem? I am running into same error.

sanketkarandikar avatar Mar 31 '22 07:03 sanketkarandikar

@sanketkarandikar , I didn't find any solution for this issue. I have been using a diffrent way without using this package.

udhayakumarcp avatar Mar 31 '22 10:03 udhayakumarcp

Hi Team,

I am also facing the same issue. i can't use this package for SSE in angular application image

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 avatar Oct 11 '22 15:10 polixisNG

@polixisNG Did that solve the No activity within 45000 milliseconds issue for you?

jbouhier avatar Oct 15 '22 00:10 jbouhier

@jbouhier unfortunately it doesn't solve the issue, I just tested it

serkyron avatar Dec 23 '22 21:12 serkyron

@serkyron what is the issue? Do you see it always? or sometimes? Do you send some message every 45 milliseconds?

Yaffle avatar Dec 24 '22 09:12 Yaffle

@serkyron Did you try with 2 minutes timeout ?

jbouhier avatar Dec 24 '22 19:12 jbouhier

@jbouhier Yes, I tried 2 minutes timeout. Same result

serkyron avatar Dec 26 '22 13:12 serkyron

@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 avatar Dec 26 '22 13:12 serkyron

@serkyron you could pass heartbeatTimeout option with a big value

Yaffle avatar Dec 26 '22 16:12 Yaffle

@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.

nolotz avatar Jan 21 '23 21:01 nolotz

Whether to consider a compromise: The server sends an invalid message every less than 45000ms to maintain the connection.

lingweihong095 avatar Apr 17 '23 07:04 lingweihong095

Anyone have an actual solution to this?

mvaljento avatar Oct 19 '23 18:10 mvaljento