Skip to content

Conversation

@kinetiknz
Copy link
Collaborator

Use a global singleton to load libaaudio.so rather than loading (and unloading) it dynamically for each cubeb context.

On Firefox CI or when running GTests locally, a crash with the following stack may occur:

#00 pc 00000000000514e8  /system/lib64/libbinder.so (android::IPCThreadState::joinThreadPool(bool)+564) (BuildId: 6feb4110d56114ae5f35c2b4f7dd713b)
#01 pc 000000000007f398  /system/lib64/libbinder.so (android::PoolThread::threadLoop()+24) (BuildId: 6feb4110d56114ae5f35c2b4f7dd713b)
#02 pc 0000000000019040  /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+248) (BuildId: 97881ed1ac37c033984e97922ff9027b)
#03 pc 000000000001b64c  /system/lib64/libutils.so (libutil_thread_trampoline(void*) (.__uniq.226528677032898775202282855395389835431)+20) (BuildId: 97881ed1ac37c033984e97922ff9027b)
#04 pc 0000000000080df8  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+232) (BuildId: 2445fc73ede03b9536eef49355aff375)
#05 pc 0000000000073dd8  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 2445fc73ede03b9536eef49355aff375)

The crash can happen after the last currently active cubeb context is closed, dependent on recent AAudio activity and scheduling of the various processes involved.

This is a result of unloading libaaudio.so when destroying a cubeb context. libaaudio.so has a global AAudioBinderClient singleton that handles Binder work. If this singleton is destroyed by unloading the DSO while BInder work is in-flight, a crash inside the Binder thread pool will occur.

Since there's no external way to know when it's safe to unload libaaudio.so and it's unnecessary to load and unload a copy for each cubeb context, we can avoid this crash by loading libaaudio.so a single time when first used and only unload it when the singleton is destroyed (as the process exits).

If the crash is still observed when unloading at process exist, we can disable unloading and "leak" the library until process exit. I'll make this change later, if it seems necessary.

@kinetiknz kinetiknz requested review from Pehrsons and padenot December 3, 2025 04:31
@kinetiknz kinetiknz self-assigned this Dec 3, 2025
Copy link
Contributor

@Pehrsons Pehrsons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid to me.

@kinetiknz kinetiknz merged commit 29e0938 into master Dec 3, 2025
31 checks passed
@kinetiknz kinetiknz deleted the aaudio_dso_singleton branch December 3, 2025 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants