[Android] SIGABRT in libaaudio prepareBuffersForStop → IsochronousClockModel::convertPositionToTime when Oboe's error thread stops the exclusive output stream

Aperta
#1,494 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
20/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
android, cpp, react-native

Direzione di ricerca

Start with the latency-hint to sharing/performance-mode mapping that #1445 changed, and the AndroidAudioPlayer error callbacks, to see exactly what latencyHint: 'interactive' opens today. The stack is in Oboe's AudioStreamAAudio.cpp (oboe_aaudio_error_thread_proc_common at line 75) and libaaudio's prepareBuffersForStop, which is only reached for a free-running MMAP endpoint. Done means either an exclusive stream no longer reaches that stop path or every error code is handled in onError with the stream torn down by the library; verifying it needs an affected Samsung device, since the report has no reproducer.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

android bug
Description

On Android, a few Samsung mid-range phones crash with SIGABRT inside libaaudio when Oboe's error thread stops the output stream, usually right after the app returns from the background. The abort happens in AudioStreamInternalPlay::prepareBuffersForStop, which only runs for a free-running (MMAP, exclusive) endpoint. AudioPlayer opens its output with SharingMode::Exclusive + PerformanceMode::LowLatency, and on 1.0.1 and main that is still what the default latencyHint: 'interactive' opens (#1445 made only balanced / playback shared).

Expected: an error on the output stream is recovered or reported, not a native crash.

Crashing thread (Oboe 1.9.3, from the AAR the library depends on):

oboe_aaudio_error_thread_proc_shared            AudioStreamAAudio.cpp:97
oboe_aaudio_error_thread_proc_common            AudioStreamAAudio.cpp:75
oboe::AudioStreamAAudio::requestStop            AudioStreamAAudio.cpp:617
oboe::AudioStreamAAudio::requestStop_l          AudioStreamAAudio.cpp:632
libaaudio_internal.so  aaudio::AudioStream::systemStopInternal
libaaudio_internal.so  aaudio::AudioStreamInternal::requestStop_l
libaaudio_internal.so  aaudio::AudioStreamInternalPlay::prepareBuffersForStop
libaaudio_internal.so  aaudio::IsochronousClockModel::convertPositionToTime
libaaudio_internal.so  <unsymbolicated>
libc.so                abort

AudioStreamAAudio.cpp:75 in Oboe 1.9.3 is the default handling in oboe_aaudio_error_thread_proc_common: onError() returned false, so Oboe runs requestStop() → onErrorBeforeClose() → close() → onErrorAfterClose(). AndroidAudioPlayer (0.13.5, 1.0.1 and main) overrides only onErrorAfterClose, so every output-stream error goes through that default requestStop().

Why it aborts (our reading of AOSP, not verified on a device):

  • AudioStreamInternalPlay::prepareBuffersForStop() returns straight away unless mAudioEndpoint->isFreeRunning(), i.e. unless the stream is MMAP exclusive with the DSP reading the buffer directly. A shared stream skips the whole block.
  • For an exclusive stream it computes mClockModel.convertPositionToTime(getFramesWritten() + framesPerBurst). IsochronousClockModel::convertDeltaPositionToTime() is (AAUDIO_NANOS_PER_SECOND * framesDelta) / mSampleRate, where framesDelta is the distance from the clock model's last marker position.
  • libaaudio is built with sanitize: { integer_overflow: true } (media/libaaudio/src/Android.bp), so an overflow in that arithmetic calls abort() instead of wrapping. The frame between convertPositionToTime and abort is unsymbolicated, which fits the sanitizer's handler.
  • Suspected trigger: after the app is backgrounded and resumed, the MMAP stream gets an error (the exclusive endpoint is taken away or invalidated), and when Oboe stops it, the clock model still holds a stale marker, so framesDelta is huge and the multiplication overflows.

Something we tried. In our app we override onError for ErrorDisconnected (stop + close the stream ourselves under the context's lock, return true). The abort still arrives through Oboe's default path in builds that include that change. So either the error code there is not ErrorDisconnected (Oboe doesn't put it in the crash), or onError bailed out early. Either way, a narrower onError does not keep the default requestStop() from running.

Possible fixes

  1. Open the output stream SharingMode::Shared and keep PerformanceMode::LowLatency. On most devices AAudio still gives a low-latency MMAP shared path through the AAudio service mixer, and prepareBuffersForStop is skipped for it. This would extend #1445 to interactive, or make exclusive opt-in.
  2. Handle every error code in onError() (return true) rather than only reacting in onErrorAfterClose. I'm not sure this is enough on its own. Oboe's contract is that the app then stops and closes the stream itself, and libaaudio's AudioStreamInternal::release_l() calls requestStop_l() on an active or disconnected stream anyway, so an exclusive stream would still reach prepareBuffersForStop. It would at least move the stop under the library's own lock and timing. Option 1 is the one that removes the path.
Steps to reproduce

No minimal reproducer yet: we see this only in production, on Samsung phones, after the app resumes from background. I don't have an affected device, and the Android emulator's audio HAL has no MMAP exclusive path, so a repro I could run there would not exercise prepareBuffersForStop. I'm reporting the stack and the code path rather than claim a repro I haven't run.

What the app does, as far as audio-api is concerned:

  1. Create an AudioContext({ sampleRate }) with the default latencyHint and play short UI sounds (AudioBufferSourceNode).
  2. suspend() the context after a short idle period; resume() it on the next play.
  3. Background the app and bring it back; the next output-stream error after resume aborts in the stack above.

Frequency: ~24 crashes from 7 users in the last month, all fatal.

Snack or a link to a repository

None. No minimal reproducer yet (see above). This report was prepared with the help of an AI assistant. The template asks AI-assisted reports to include a verified MRE, and we could not build one that actually reproduces without the affected hardware, so we're saying so rather than attaching an unverified one.

React Native Audio API version

0.13.5 (Oboe 1.9.3). The relevant code is unchanged on 1.0.1 and main for the default interactive hint.

React Native version

0.88.0

Platforms

Android

JavaScript runtime

Hermes

Workflow

Expo Dev Client (Expo prebuild; crashes are from EAS release builds)

Architecture

Fabric (New Architecture)

Build type

Release app & production bundle

Device

Real device

Device model

Samsung Galaxy A36 5G (SM-A366B, SM-A366E) and SM-A276B, Android 15 (21 events) and Android 16 (3 events)

Acknowledgements

Yes. I searched this repo (open and closed) for prepareBuffersForStop, convertPositionToTime, IsochronousClockModel, requestStop, SIGABRT, abort, MMAP, onErrorAfterClose and error callback. Nearest but different: #1088 and #1328 (error-callback recovery, not this abort), #1231 / #1232 / #1445 (sharing and performance mode for latency hints). In google/oboe I found nothing for prepareBuffersForStop, convertPositionToTime, requestStop_l or systemStopInternal. The closest there is google/oboe#1489, also an abort inside libaaudio's timestamp math, but on the legacy (AudioStreamLegacy::getBestTimestamp) path, not MMAP stop.

Lingua principale
C++
Stelle
864
Fork
103
Merge medio
1g 16h
PR unite (30g)
77

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di software-mansion/react-native-audio-api

Tutte le issue di software-mansion/react-native-audio-api

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.