SSEvents - Problems closing the connection

We have a server side event connection.

We close the connection with this.


It runs without an error, but seconds later we get another connection.

We read this post

And found your comment that we should call


But then we see this

Error logged: TypeError: Cannot read property 'readyState' of null
at sendHeartbeat (ss-utils.js:728)
at eval (platform-implementation.js:47)
at Function.value (platform-implementation.js:47)
at eval (platform-implementation.js:47) 

Original error stack:
TypeError: Cannot read property 'readyState' of null
    at sendHeartbeat (chrome-extension://ljcdojknmlicdfoijbipailgnjfpmlmh/lib/ss-utils.js:728:54)

This is occurring in ss-utils.js:728

     if ($.ss.eventSource.readyState === 2) //CLOSED

We attempted to check for nulls at line 728, but then we had stack traces in other places.

Any ideas?


What is connection in connection.close() ?


You should only be calling $.ss.disposeServerEvents() which also closes the EventSource connection, not doing both.

we removed the close() and we still get errors.

It appears that this function is getting called after the $.ss.disposeServerEvents(); is getting executed. Thats why $.ss.eventSource == null .

The eventhandler for the sendHeart beat is called when eventsource == null.

   // ssutils.js  line 725
    function sendHeartbeat() 
       if (connectId !== $.ss.CONNECT_ID) 
       if ($.ss.eventSource.readyState === 2) //CLOSED
           var stopFn = $.ss.handlers["onStop"];
           if (stopFn != null)
          $.ss.reconnectServerEvents({ errorArgs: { error:'CLOSED' } });

I added a null check on line 726. It appears to work without throwing errors.

But i dont know if im breaking something else.

if ($.ss.eventSource == null) return;

Iā€™m also short-circuiting it in this commit. Will be available in the next ServiceStack v5.9.3+ on MyGet after it runs through CI or available now from:

1 Like