Fix sd-bus thread-safety crash in Linux tray (#405)#407
Merged
Conversation
sd-bus objects are not thread-safe, but the event-loop thread (sd_bus_process) and the JVM threads driving the sni_tray_set_*/ sni_tray_item_* mutators (sd_bus_emit_*) accessed tray->bus with no synchronization. Under frequent updates an emit races with an in-flight sd_bus_process and trips 'Assertion !bus->current_slot ... Aborting'. - Add a bus_lock mutex serializing all sd_bus_* access and the tray state it touches: held across setup, each sd_bus_process batch and teardown, and acquired by every public mutator. - Defer user callbacks (click / menu) through a queue flushed by the event loop after releasing bus_lock, so upcalls into Kotlin can re-enter the mutators without deadlocking against the caller's lock. - Add a standalone C concurrency regression test that aborts on the old code and passes on the fixed code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #405 —
Assertion '!bus->current_slot' failed at ... bus_process_internal(). Aborting.sd-busobjects are not thread-safe. Insni.cthe event-loop thread (sni_tray_run→sd_bus_process) and the JVM threads driving everysni_tray_set_*/sni_tray_item_*/sni_tray_add_*mutator (→sd_bus_emit_*) accessed the sametray->buswith zero synchronization. Under frequent icon/menu updates an emit races with an in-flightsd_bus_processand trips the internalcurrent_slotassertion, aborting the process.Changes
bus_lockmutex that serializes allsd_bus_*access and the tray state it reads/writes — held across bus setup, eachsd_bus_processbatch, and teardown, and acquired by every public mutator.bus_lock. This avoids holding the bus lock across an upcall into Kotlin, which would otherwise deadlock against theLinuxTrayManagerReentrantLock(lock inversion when a callback re-enters the mutators).test_sni_concurrency.c+run_concurrency_test.sh).Test plan
!bus->current_slotassertion)build.shrebuildslibLinuxTray.soclean with-Wall -Wextra(no new warnings)Run the test:
./src/native/linux/run_concurrency_test.sh(uses a privatedbus-run-session).