-
Notifications
You must be signed in to change notification settings - Fork 404
fix(mercury): gracefully handle mercury rebalancing #5106
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
Changes from 5 commits
8e0f835
a9a8559
9c0d114
a2edad1
56582c3
63518ca
5c9472e
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 |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import { | |
| } from './errors'; | ||
|
|
||
| const normalReconnectReasons = ['idle', 'done (forced)', 'pong not received', 'pong mismatch']; | ||
| const MERCURY_CLOSE_4000_METRIC = 'JS_SDK_MERCURY_CLOSE_4000'; | ||
|
|
||
| const Mercury = WebexPlugin.extend({ | ||
| namespace: 'Mercury', | ||
|
|
@@ -882,6 +883,29 @@ const Mercury = WebexPlugin.extend({ | |
| return handlers; | ||
| }, | ||
|
|
||
| _submitMercuryClose4000Metric(sessionId, event, options) { | ||
| const {action, isActiveSocket, messageType} = options; | ||
|
|
||
| try { | ||
| this.webex.internal.metrics.submitClientMetrics(MERCURY_CLOSE_4000_METRIC, { | ||
| fields: { | ||
| action, | ||
| close_code: event.code, | ||
| close_reason: event.reason || '', | ||
| is_active_socket: isActiveSocket, | ||
| message_type: messageType, | ||
| session_id: sessionId, | ||
| }, | ||
| tags: { | ||
| action, | ||
| message_type: messageType, | ||
| }, | ||
| }); | ||
| } catch (error) { | ||
| this.logger.warn(`${this.namespace}: failed to submit Mercury 4000 close metric`, error); | ||
| } | ||
| }, | ||
|
|
||
| _onclose(sessionId, event, sourceSocket) { | ||
| // I don't see any way to avoid the complexity or statement count in here. | ||
| /* eslint complexity: [0] */ | ||
|
|
@@ -938,9 +962,28 @@ const Mercury = WebexPlugin.extend({ | |
| break; | ||
| case 4000: | ||
| // metric: disconnect | ||
| this.logger.info(`${this.namespace}: socket ${sessionId} replaced; will not reconnect`); | ||
| if (isActiveSocket) this._emit(sessionId, 'offline.replaced', event); | ||
| // If not active, nothing to do | ||
| if (reason === 'replaced') { | ||
|
rsarika marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: The comparison reason === 'replaced' is case-sensitive. If there's any chance the server could send 'Replaced' or 'REPLACED', a safer check would be:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, its already there at declaration const reason = event.reason && event.reason.toLowerCase(); |
||
| this._submitMercuryClose4000Metric(sessionId, event, { | ||
| action: 'no_action', | ||
| isActiveSocket, | ||
| messageType: 'replaced', | ||
| }); | ||
| this.logger.info(`${this.namespace}: socket ${sessionId} replaced; will not reconnect`); | ||
| if (isActiveSocket) this._emit(sessionId, 'offline.replaced', event); | ||
| } else { | ||
| this._submitMercuryClose4000Metric(sessionId, event, { | ||
| action: isActiveSocket ? 'reconnect' : 'ignore_non_active', | ||
| isActiveSocket, | ||
| messageType: 'other', | ||
| }); | ||
| this.logger.info( | ||
| `${this.namespace}: socket ${sessionId} disconnected with 4000: ${event.reason}; reconnecting` | ||
| ); | ||
| if (isActiveSocket) { | ||
| this._emit(sessionId, 'offline.transient', event); | ||
| this._reconnect(socketUrl, sessionId); | ||
| } | ||
| } | ||
| break; | ||
| case 4001: | ||
| // replaced during shutdown | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.