Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No activity within 45000 milliseconds. Reconnecting. #143

Open
BishoyBishai opened this issue Jan 24, 2020 · 22 comments
Open

No activity within 45000 milliseconds. Reconnecting. #143

BishoyBishai opened this issue Jan 24, 2020 · 22 comments

Comments

@BishoyBishai
Copy link

No description provided.

@akaskj
Copy link

akaskj commented Jan 30, 2020

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

@tiimoS
Copy link

tiimoS commented Feb 26, 2020

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

@henry-chris
Copy link

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

@Vaggal
Copy link

Vaggal commented Feb 16, 2021

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.

@faizansalamat
Copy link

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

@MrJimmyYi
Copy link

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

@udhayakumarcp
Copy link

Hi Team,

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

@cwirz
Copy link

cwirz commented Jan 12, 2022

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

@udhayakumarcp
Copy link

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

  1. Module not found error EventSource/eventsource#234
  2. Angular Event source is not a constructor error EventSource/eventsource#235
  3. ERROR TypeError: (intermediate value)(intermediate value)(intermediate value).request is not a function EventSource/eventsource#236

Is there any working example for Angular?

@sanketkarandikar
Copy link

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

@udhayakumarcp
Copy link

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

@polixisNG
Copy link

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();
                            }

@jbouhier
Copy link

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

@serkyron
Copy link

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

@Yaffle
Copy link
Owner

Yaffle commented Dec 24, 2022

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

@jbouhier
Copy link

@serkyron Did you try with 2 minutes timeout ?

@serkyron
Copy link

serkyron commented Dec 26, 2022

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

@serkyron
Copy link

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

@Yaffle
Copy link
Owner

Yaffle commented Dec 26, 2022

@serkyron you could pass heartbeatTimeout option with a big value

@nolotz
Copy link

nolotz commented Jan 21, 2023

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

@lingweihong095
Copy link

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

@mvaljento
Copy link

Anyone have an actual solution to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests