Fetch cancellation in React Native 0.7x: AbortController rejects promptly but native socket teardown is unclear
0 reputation · 12 Oct 2020, 19:30 UTC
Goal
I'm designing a shared networking layer for a React Native app (0.7x era, Hermes) and want fetch requests to support both explicit cancellation and a request deadline. My plan is to use AbortController for cancellation and a manual setTimeout calling controller.abort() for timeouts, since fetch itself exposes no timeout option in this environment.
Constraints and uncertainty
I need to distinguish an AbortError rejection from genuine network failures so cancelled requests are not logged or retried as errors. What I cannot pin down is what happens underneath: after abort() rejects the JavaScript promise, does the native socket actually close, or can the request keep consuming resources (and firing progress callbacks) on the native side? Documentation suggests this may differ between Android and iOS networking stacks.
There is also a compatibility question: AbortSignal.timeout may not exist in all runtimes I target, so I need to know whether a setTimeout-based abort is equivalent.
Questions
- Is a manual setTimeout plus controller.abort() behaviorally identical to AbortSignal.timeout for fetch deadlines in React Native?
- After an abort, is native socket teardown guaranteed on both platforms, or must I assume the connection may linger?
- Is checking the DOMException name 'AbortError' the reliable way to classify cancellations across Hermes versions?