Ti.Network.HTTPClient: abort() vs timeout for request termination
0 reputation · 17 Sept 2024, 02:40 UTC
0 reputation · 17 Sept 2024, 02:40 UTC
When managing long-running network requests in Appcelerator Titanium, there is a trade-off between using the timeout property and the abort() method to handle unresponsive servers or user-initiated cancellations.
The timeout property ensures a request fails automatically after a set duration, typically triggering the onerror callback. In contrast, abort() allows for immediate termination of a pending request without waiting for the timeout threshold to be reached.
The uncertainty lies in the consistency of callback execution across iOS and Android builds. It is unclear if calling abort() synchronously triggers the onerror callback with a specific error code, or if it simply halts the request without notifying the application state.
abort() consistently trigger the onerror callback across both platforms?37775 reputation · 17 Sept 2024, 06:46 UTC
No. abort() does not consistently trigger onerror on both iOS and Android, and there is no safe, platform-independent abort error code to hardcode. The timeout property is the more predictable way to force a failure after a deadline, though its error payload can still differ between native stacks. Treat abort() as a best-effort cancellation, not a guaranteed error event.
Likely explanation: Titanium hands HTTP work to platform-native networking libraries. iOS and Android map request cancellation to JavaScript events differently, and that mapping has shifted across Titanium SDK releases. One build may fire onerror after abort() while another silently stops the request.
Established behavior:
timeout is set in milliseconds and causes a pending request to fail automatically when no response arrives within that window, generally routing to onerror.abort() attempts to cancel an in-flight request immediately and is normally used for user-initiated cancellation or unresponsive endpoints.code and message fields, but field names and values are not guaranteed across SDK versions.abort() after the request completes, or calling it multiple times, may produce no callback.timeout on long-running requests so unresponsive servers cannot block indefinitely.onerror and onload before send(), and log the full error object instead of assuming a specific code.abort() only for immediate cancellation, such as a user tapping Cancel, and guard it so it cannot run after completion.tiapp.xml before relying on abort semantics.Which Titanium SDK version and target iOS/Android versions are you building against? Abort callback behavior is version-dependent, so that detail determines whether to treat abort() as an error event or as a silent stop with fallback cleanup.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.