#50706·expo

[expo-audio][android] AudioRecordingServiceConnection.bindWithService can suspend forever: startBindingTimeout() is never called

Author: carlesfernandeztenaCreated Sep 28, 2026Updated Sep 28, 2026
Labelsneeds reviewcontributor: external

Minimal reproducible example

https://github.com/carlesfernandeztena/expo-audio-background-recording-repro (same app as issue 1: it exercises the bind path. The hang itself can't be triggered on demand; see the steps.)

Steps to reproduce

Platform: Android, background recording on (allowsBackgroundRecording: true). This is a code-level finding: we haven't been able to trigger the hang on demand. It needs the recording service bind to never deliver a callback.

bindWithService() suspends until onServiceConnected, onBindingDied or onNullBinding resumes the continuation: https://github.com/expo/expo/blob/990f8adff1d9aa350671515fcc32364c1fab8811/packages/expo-audio/android/src/main/java/expo/modules/audio/service/AudioRecordingServiceConnection.kt#L58-L88

There are two ways the continuation is never resumed, so prepareToRecordAsync() never settles:

  1. The bind never calls back. startBindingTimeout() exists for exactly this case, but nothing calls it. So if bindService() returns true but the system never reports a connection (OEM process restrictions, or the service process dying mid-bind), the promise hangs forever. Definition of the timeout that is never called: https://github.com/expo/expo/blob/990f8adff1d9aa350671515fcc32364c1fab8811/packages/expo-audio/android/src/main/java/expo/modules/audio/service/AudioRecordingServiceConnection.kt#L39-L48
  2. The React context is gone. In that branch, onBindingFailed(...) only logs, then return@suspendCoroutine exits without resuming (L73-L75).

Expected: prepareToRecordAsync() rejects within a bounded time, so the app can recover.

Actual: the promise can stay pending forever, so an app that awaits it is stuck in its "starting to record" state with no way to recover.

Suggested fix:

diff
         transitionToState(ServiceBindingState.BINDING)
         bindingContinuation = continuation
+        startBindingTimeout()
       }

In the React-context-lost branch, also resume with an exception, like the !serviceRunning branch does:

diff
         val reactContext = appContext.reactContext ?: run {
           onBindingFailed("Binding with the expo-audio playback service failed: React context lost")
+          continuation.resumeWithException(AudioRecordingServiceException("React context lost"))
           return@suspendCoroutine
         }

Environment

  expo-env-info 2.1.0 environment info:
    System:
      OS: Linux 6.6 Ubuntu 24.04.4 LTS 24.04.4 LTS (Noble Numbat)
      Shell: 5.2.21 - /bin/bash
    Binaries:
      Node: 24.13.0 - /home/carles/.nvm/versions/node/v24.13.0/bin/node
      Yarn: 1.22.22 - /home/carles/.nvm/versions/node/v24.13.0/bin/yarn
      npm: 11.6.2 - /home/carles/.nvm/versions/node/v24.13.0/bin/npm
    SDKs:
      Android SDK:
        API Levels: 31, 35, 36
        Build Tools: 34.0.0, 35.0.0, 36.0.0
    npmPackages:
      expo: ~57.0.25 => 57.0.25
      react: 19.2.3 => 19.2.3
      react-native: 0.86.3 => 0.86.3
    npmGlobalPackages:
      eas-cli: 20.5.0
    Expo Workflow: managed

Expo Doctor Diagnostics

Running 21 checks on your project...
21/21 checks passed. No issues detected!

Related: #50705 (same code path, different failure).