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

オープン
#1,494 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
20/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
android, cpp, react-native

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C++
スター
864
フォーク
103
平均マージ
1日 16時間
マージ済み PR(30日)
77

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

software-mansion/react-native-audio-api のほかの issue

software-mansion/react-native-audio-api の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。