-
-
Couldn't load subscription status.
- Fork 1.3k
Add a watchdog for the heartbeat #601
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,6 +172,7 @@ SockJS.CONNECTING = 0; | |
| SockJS.OPEN = 1; | ||
| SockJS.CLOSING = 2; | ||
| SockJS.CLOSED = 3; | ||
| SockJS.WATCHDOG_WEBSOCKET_TIMEOUT = 30000; // The heartbeat appears every 25 seconds, so we have 5 seconds delay buffer | ||
|
|
||
| SockJS.prototype._receiveInfo = function(info, rtt) { | ||
| debug('_receiveInfo', rtt); | ||
|
|
@@ -241,6 +242,11 @@ SockJS.prototype._transportTimeout = function() { | |
| } | ||
| }; | ||
|
|
||
| SockJS.prototype._websocketWatchdogCb = function(websocket) { | ||
| debug("watchdog websocket timeout"); | ||
| websocket._close(1006, 'Server lost session'); | ||
| }; | ||
|
|
||
| SockJS.prototype._transportMessage = function(msg) { | ||
| debug('_transportMessage', msg); | ||
| var self = this | ||
|
|
@@ -257,6 +263,8 @@ SockJS.prototype._transportMessage = function(msg) { | |
| case 'h': | ||
| this.dispatchEvent(new Event('heartbeat')); | ||
| debug('heartbeat', this.transport); | ||
| clearTimeout(this.heartbeatWatchdog); | ||
| this.heartbeatWatchdog = setTimeout(this._websocketWatchdogCb, SockJS.WATCHDOG_WEBSOCKET_TIMEOUT, this); | ||
|
||
| return; | ||
| } | ||
|
|
||
|
|
@@ -321,6 +329,7 @@ SockJS.prototype._open = function() { | |
| this.transport = this._transport.transportName; | ||
| this.dispatchEvent(new Event('open')); | ||
| debug('connected', this.transport); | ||
| this.heartbeatWatchdog = setTimeout(this._websocketWatchdogCb, SockJS.WATCHDOG_WEBSOCKET_TIMEOUT, this); | ||
| } else { | ||
| // The server might have been restarted, and lost track of our | ||
| // connection. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter name 'websocket' is misleading as it refers to the SockJS instance, not a WebSocket. This should be 'sockjs' or 'self' to accurately reflect what it represents.