fix(socket-mode): observe reconnect rejections#2657
Conversation
|
|
Thanks for the contribution! Before we can merge this, we need @w3lld1 to sign the Salesforce Inc. Contributor License Agreement. |
|
Hi @w3lld1 👋🏻 Thanks for the pull request! 🙇🏻 ❓ Can you please sign our CLA - once signed, we can begin reviewing your pull request and enabling the workflow checks. |
| this.delayReconnectAttempt(this.start); | ||
| void this.delayReconnectAttempt(this.start).catch((error) => { | ||
| if (!this.shuttingDown) { | ||
| this.logger.error(`Failed to reconnect Socket Mode client: ${error}`); |
There was a problem hiding this comment.
praise: Nice - the if (!this.shuttingDown) guard here is great. It surfaces the real reconnect failure while keeping the log quiet during a normal disconnect() race, which is the whole point of the fix. Thanks for the care.
| return new Promise((resolve, reject) => { | ||
| setTimeout(() => { | ||
| if (this.shuttingDown) { | ||
| this.logger.debug('Client shutting down, will not attempt reconnect.'); |
There was a problem hiding this comment.
suggestion: We should handle this differently. Resolving with undefined as T works for the close-handler, but retrieveWSSURL also calls delayReconnectAttempt (line 276) and uses the result as a WebSocket URL.
If disconnect() races a retry inside retrieveWSSURL, this now returns undefined up through the recursion and start() ends up constructing new SlackWebSocket({ url: undefined, ... }). Not ideal.
A couple of options come to mind:
- Short-circuit earlier so we never call into
start()/ return a URL when we know we're shutting down. This may match the approach throughout the package. - Reject with a specific "shutdown in progress" error and have callers (both the
closehandler andretrieveWSSURL) swallow it explicitly. That keeps the type honest and avoids theundefined-as-URL path.
| }); | ||
|
|
||
| describe('reconnect', () => { | ||
| it('should observe a rejected reconnect attempt', async () => { |
There was a problem hiding this comment.
praise: Really appreciate having a regression test alongside the fix - it locks in the main failure mode from #2656.
| client.emit('close'); | ||
| await sleep(10); | ||
|
|
||
| sinon.assert.calledWith(errorLog, 'Failed to reconnect Socket Mode client: Error: reconnect failed'); |
There was a problem hiding this comment.
suggestion: We should add a second test case here that covers the !this.shuttingDown guard.
Signed-off-by: w3lld1 <42353747+w3lld1@users.noreply.github.com>
|
Addressed both review points in Validation: the socket-mode unit suite passes (22 tests), the full repository Biome check passes, and |
|
Thanks for the review. The follow-up commit
Fresh validation:
The remaining CLA signature requires the account holder to complete the Salesforce CLA form manually. |
Summary
Fixes #2656
Validation
npm run lintnpm run buildnpm run test:unit --workspace=@slack/socket-mode(21 tests passed)Requirements