fix: Fix StaticIntervalPollingController not properly stopping polling if _executePoll was still pending#4230
Conversation
StaticIntervalPollingController not properly stopping polling if _executePoll was still pending
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
…imeout' into jl/fix-static-interval-polling-timeout
|
Details |
| }); | ||
|
|
||
| it('should start and stop polling sessions for different networkClientIds with the same options', async () => { | ||
| controller.setIntervalLength(TICK_TIME); |
There was a problem hiding this comment.
pretty minor but was this always extraneous?
There was a problem hiding this comment.
yeah, this is set in the beforeEach already
| it('should stop polling session after current iteration if stop is requested while current iteration is still executing', async () => { | ||
| const pollingToken = controller.startPollingByNetworkClientId('mainnet'); | ||
| await advanceTime({ clock, duration: 0 }); | ||
| expect(controller._executePoll).toHaveBeenCalledTimes(1); | ||
| controller.stopPollingByPollingToken(pollingToken); | ||
| controller.executePollPromises[0].resolve(); | ||
| await advanceTime({ clock, duration: TICK_TIME }); | ||
| expect(controller._executePoll).toHaveBeenCalledTimes(1); | ||
| await advanceTime({ clock, duration: TICK_TIME }); | ||
| expect(controller._executePoll).toHaveBeenCalledTimes(1); | ||
| controller.stopAllPolling(); | ||
| }); |
There was a problem hiding this comment.
Not blocking but should we do a version of this test where we have multiple polling keys running?
There was a problem hiding this comment.
not sure if necessary since we have other tests that specifically test that stopping polling for one key does not stop polling for other keys
There was a problem hiding this comment.
Fair yeah I guess I'm wondering about a test like starting polling sessions for a few keys and then calling stopAllPolling before execution resolves for both.
adonesky1
left a comment
There was a problem hiding this comment.
LGTM! Just one non-blocking request for an additional test
…imeout' into jl/fix-static-interval-polling-timeout
Explanation
Currently, there is a bug in the StaticIntervalPollingController that causes polling to not be properly stopped if a stop is requested while
_executePollhas not yet resolved for the current loop. This PR adds a guard to check if the id returned by setTimeout still matches what is in state, indicating that polling is still active.References
Changelog
@metamask/polling-controllerStaticIntervalPollingControllerOnly,StaticIntervalPollingController, andStaticIntervalPollingControllerV1now properly stops polling when a stop is requested while_executePollhas not yet resolved for the current loopChecklist