mbalsam
September 21, 2020, 10:33pm
1
We have a server side event connection.
We close the connection with this.
connection.close()
It runs without an error, but seconds later we get another connection.
We read this post
https://forums.servicestack.net/t/sse-connecting-twice-if-session-terminated-at-server/8625/12
And found your comment that we should call
connection.close()
$.ss.disposeServerEvents();
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?
Mitch
mythz
September 22, 2020, 6:39am
2
What is connection
in connection.close()
?
mbalsam
September 22, 2020, 5:10pm
3
mythz
September 22, 2020, 7:40pm
4
You should only be calling $.ss.disposeServerEvents()
which also closes the EventSource
connection, not doing both.
mbalsam
September 22, 2020, 7:53pm
5
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)
return;
if ($.ss.eventSource.readyState === 2) //CLOSED
{
var stopFn = $.ss.handlers["onStop"];
if (stopFn != null)
stopFn.apply($.ss.eventSource);
$.ss.reconnectServerEvents({ errorArgs: { error:'CLOSED' } });
return;
}
mbalsam
September 22, 2020, 8:00pm
6
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;
mythz
September 22, 2020, 8:04pm
7
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: https://unpkg.com/ss-utils/ss-utils.js
1 Like