-
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
base: next
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 |
|---|---|---|
|
|
@@ -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', | ||
|
|
@@ -850,6 +851,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] */ | ||
|
|
@@ -901,9 +925,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') { | ||
|
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.
When the active socket closes with code Useful? React with 👍 / 👎. |
||
| 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 | ||
|
|
||
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.
When the client-metrics request fails asynchronously—such as during the same network disruption that closed Mercury—
submitClientMetrics()returns a rejected promise, but this call discards it. The surroundingtry/catchonly handles synchronous throws, so the failure becomes an unhandled rejection and can terminate Node clients instead of merely logging the metric failure as intended; attach a rejection handler to the returned promise.Useful? React with 👍 / 👎.