EventSource icon indicating copy to clipboard operation
EventSource copied to clipboard

Every 45000 milliseconds retry request again and again

Open MrJimmyYi opened this issue 3 years ago • 6 comments

I met a problem: "No activity within 45000 milliseconds. Reconnecting" I use EventSourcePolyfill.But the background response time may take 5 minutes more than 45 seconds by default. I tried many methods, but they are all failed. How to set its reconnection time according to custom Settings?

MrJimmyYi avatar Sep 24 '21 06:09 MrJimmyYi

Hi! I found a solution in eventsource.js

> eventsource.js

function start(es, url, options){ ... var heartbeatTimeout = parseDuration(options.heartbeatTimeout, 45000); ... } Look! Our default 45000 and custom heartbeat times are here.

So, I tried to modify this line of code , Here is my modified code: var heartbeatTimeout = parseDuration(options.headers.heartbeatTimeout, 45000);

Then I added heartbeatTimeout in the header to specify 3 minutes: new EventSourcePolyfill(url,{ headers: { heartbeatTimeout: 180*1000 } })

Because I'm using Spring SseEmitter ,the server also sets a timeout period of 10 minutes: SseEmitter sseEmitter = new SseEmitter(600000L);

This means I retry to connect to the server every 3 minutes during the 10-minute validity period

So, it worked,Won't retry to connect the server every 45 seconds, using a custom 5-minute time limit for requests instead. Perfect! b81f135b8cc5a229631e7c794259e11e ab02c55471cd6a298e5204068f64449c

MrJimmyYi avatar Sep 24 '21 07:09 MrJimmyYi

image

udhayakumarcp avatar Jan 05 '22 12:01 udhayakumarcp

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

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

@MrJimmyYi I tried your solution, but no matter what changes I do in eventSource.js and pass heartbeatTimeout in headers, it is not reflecting. What could be wrong?

sanketkarandikar avatar Mar 31 '22 07:03 sanketkarandikar