Server requests accumulating indefinately

There is no error, the application continues to work, so it is not stuck in ss-utils. Just event-source GET is not reissued. Is there a place in ss-util to put breakpoint for tracking this?

A failed heartbeat should execute this code which does the reconnecting.

Sorry for delay, I missed notification about your response.

I think I understand why it does not work.

When IISRESET is issued, reconnectServerEvents gets control, it closes the previous EventSource and opens a new one. When ā€˜onConnect’ message comes, heartbeat resumes and reconnectServerEvents is assigned again as error function for AJAX.

However new EventSource fails to connect since IISRESET lasts number of seconds (~20 in our case), so onConnect never comes.

Any idea how to fix this?

Can you let me know if this helps:

$.ss.handlers.onReconnect = function() { 
  this.onerror = function() { $.ss.reconnectServerEvents({ errorArgs: arguments }); };
};

Tried but nothing changed.
Was I supposed to put it into the application code?

Yeah after the call to $(source).handleServerEvents({ ... });

Can you try adding logging to see if it’s getting called, e.g:

$.ss.handlers.onReconnect = function() { 
    this.onerror = function() { 
        console.log("EventSource Error, reconnecting...", arguments, this);
        $.ss.reconnectServerEvents({ errorArgs: arguments }); 
    };
};

If it logs anything can you post it here?

Yes, I put it after handleServerEvents

No, the message does not appear on console.

Hmm, weird EventSource isn’t raising an error event when it can’t connect, can you try adding it on the EventSource instance directly:

source.onerror = function() { 
    console.log("EventSource Error, reconnecting...", arguments, this);
    $.ss.reconnectServerEvents({ errorArgs: arguments }); 
};

If there’s no change try using a timer:

$.ss.handlers.onReconnect = function() {
    window.setTimeout(function() {
        if (!$.ss.eventSource || $.ss.eventSource.readyState == 2)
            $.ss.reconnectServerEvents();
    }, 10000);
};

Now it works (the first variant).
However it tries to reconnect many times until IISRESET terminates.
Can we add a delay between reconnection attempts?

You can try merging them :slight_smile:

source.onerror = function() { 
    window.setTimeout(function() {
        if (!$.ss.eventSource || $.ss.eventSource.readyState == 2)
            $.ss.reconnectServerEvents();
    }, 10000);
};

Somehow this does not help, I put timeout of 2 sec, still many event-stream request and messages appeared every second.

Sorry, my fault, compilation failed, I’ll retest now.

It works now, thanks a lot.

1 Like