Redux-Saga race timeout leaves pending API request unresolved
0 reputation · 22 Mar 2023, 03:16 UTC
Goal
When a Redux-Saga task races an asynchronous API call against a delay effect to implement a timeout, the timer should win cleanly and prevent any late response from updating state.
Constraint
Cancelling a saga task interrupts the generator and runs finally blocks, but it does not automatically cancel the underlying Promise or network request passed to call. The request can continue after the saga treats the operation as timed out, creating a race between a delayed error action and a belated success response.
Does saga cancellation terminate the underlying fetch, or only the generator? Should the API call receive an AbortSignal from the timeout handler, and where should the controller be created relative to race? If the original promise resolves after the delay wins, what prevents its result from dispatching a state-changing action?