socket-mode: fix bug when apps.connections.open
returns an error and won't retry
#1735
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1500.
The root of the bug seems to be when trying to
emit
to a state from withinsetTimeout
wrapper function. The fix is to return a promise in thedo
state machine function, resolve the promise after the dynamic waiting period, and useonSuccess
andtransitionTo
to transition to the correct state.You can test the faulty behaviour by running the test in this PR against the unmodified code prior to the changes introduced in this PR. It helps to set the client's log level to DEBUG to get insight into behaviour. Without the patch in this PR, the debug output would look like this if
apps.connections.open
returns an error:.. and will sit stuck there (because the state is not being transitioned).
With the patch in this PR, the logs now are (with the test simulating two calls to
apps.connections.open
failing but succeeding on the third one):