Skip to content

Android XMLHttpRequest timeout error trigger onerror instead of ontimeout #55081

@weihanyau

Description

@weihanyau

Description

On Android, the XMLHttpRequest implementation is incorrectly triggering onerror instead of ontimeout. Causing timeout error to be handled as generic error.

Investigated this and found out that this is caused by the switch from using connectTimeout to callTimeout for okHttp in #38953. callTimeout will throw InterruptedIOException instead of SocketTimeoutException but the timeout error catch logic is never updated after the change.

Created #55080 to fix the issue.

Steps to reproduce

  1. Create new XMLtHttpRequest
  2. Set a timeout, eg. 3 seconds
  3. Add onerror and ontimeout event handler
  4. Call an endpoint that will surely timeout, eg. using an online http request and response service https://httpbin.org/delay/10 (this endpoint will return a delayed response in 10 seconds)
  5. Notice that the onerror handler is called instead of ontimeout

React Native Version

0.83.1

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info

System:
  OS: macOS 15.7.2
  CPU: (10) arm64 Apple M2 Pro
  Memory: 132.50 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 24.11.1
    path: /Users/weihan.yau/.nvm/versions/node/v24.11.1/bin/node
  Yarn:
    version: 1.22.22
    path: /opt/homebrew/bin/yarn
  npm:
    version: 11.6.2
    path: /Users/weihan.yau/.nvm/versions/node/v24.11.1/bin/npm
  Watchman:
    version: 2024.12.02.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/weihan.yau/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.1
      - iOS 26.1
      - macOS 26.1
      - tvOS 26.1
      - visionOS 26.1
      - watchOS 26.1
  Android SDK: Not Found
IDEs:
  Android Studio: 2025.2 AI-252.27397.103.2522.14617522
  Xcode:
    version: 26.1/17B55
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 21.0.8
    path: /Users/weihan.yau/.jenv/shims/javac
  Ruby:
    version: 2.7.8
    path: /Users/weihan.yau/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.0
    wanted: 20.0.0
  react:
    installed: 19.2.0
    wanted: 19.2.0
  react-native:
    installed: 0.83.1
    wanted: 0.83.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Stacktrace or Logs

-

MANDATORY Reproducer

https://github.com/weihanyau/rn-android-uncaught-timeout

Screenshots and Videos

Current Expected
reproducer-timeout-failed.webm
reproducer-timeout-success.webm

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions