Repository navigation
Description
Describe the bug
FluidVoice permanently freezes (spinning beachball on its windows, menu bar item unresponsive, 0% CPU) due to a main-thread deadlock triggered by a default audio device change while the app is idle. The app never recovers; force quit is the only way out.
I captured a sample of the hung process, and every one of the 2,557 snapshots shows the same two threads waiting on each other:
Thread A — main thread. The CoreAudio default-device-change listener (dispatched to main from registerDefaultDeviceChangeListener()) runs scheduleAudioRouteRecovery → retireAudioEngine(reason: "idle_route_change:..."). Inside retireAudioEngine, the final strong reference to the old AVAudioEngine is released on the main thread. -[AVAudioEngine dealloc] then does a synchronous dispatch onto the engine's internal engine serial queue and blocks in __DISPATCH_WAIT_FOR_QUEUE__.
Thread B — the engine's internal engine queue. The same device change is being handled by AVAudioEngineImpl::IOUnitConfigurationChanged(), which posts AVAudioEngineConfigurationChange via NSNotificationCenter. Because ASRService registers that observer with queue: .main (ASRService.swift#L2317-L2322), notification delivery wraps the handler in an NSOperation on the main queue and blocks the posting thread in -[NSOperation waitUntilFinished] until the main thread runs it.
Thread A is waiting for Thread B's queue; Thread B is waiting for Thread A's queue. Circular wait, so the hang is permanent.
Two observations from the source that may help:
retireAudioEnginealready tries to avoid exactly this by deferring the release ofengineStorageto a background queue (ASRService.swift#L605-L610). The sample shows-[AVAudioEngine dealloc]occurring on the main thread directly underretireAudioEngineregardless, so some other strong reference to the engine is being dropped synchronously inside that function (Swift release/inlined frames don't show in the sample, so I can't say which one from the trace alone).- The
AVAudioEngineConfigurationChangeobserver body only spawns aTask { @MainActor ... }, so registering it withqueue: nil(synchronous delivery on the posting thread) looks safe and would remove thewaitUntilFinishedon the main queue — breaking the cycle from the other side even if a main-thread dealloc slips through again.
Reproduction steps
It is a race between the app's route-recovery teardown and the engine's own configuration-change handling, so it does not reproduce on demand. Conditions when it hit:
- FluidVoice running and idle (not recording), "sync audio devices with system" enabled.
- The system default input/output device changes (in my case most likely a Bluetooth headset connecting or disconnecting).
- If the engine's internal queue is inside
IOUnitConfigurationChanged()posting the configuration-change notification at the moment the main thread releases the engine inretireAudioEngine, the app deadlocks.
Expected behavior
The idle route change retires and re-prewarms the audio engine; the app keeps working.
Actual behavior
The app freezes permanently: UI unresponsive, 0% CPU, all samples identical over a 3-second sample window. It stayed in this state indefinitely (hours) until I killed the process. Plain SIGTERM was enough to terminate it; after relaunch everything worked normally.
App Version
1.6.2 (build 13)
macOS Version
macOS 26.5.1 (25F80)
Architecture
Apple Silicon (arm64)
Logs or crash report
Main thread (Thread A), trimmed from sample output — identical in all 2,557 snapshots:
2557 Thread_2049822 DispatchQueue_1: com.apple.main-thread (serial)
...
2557 _dispatch_call_block_and_release (in libdispatch.dylib)
2557 <deduplicated_symbol> (in FluidVoice)
2557 partial apply for closure #1 in closure #1 in ASRService.registerDefaultDeviceChangeListener() (in FluidVoice)
2557 ASRService.scheduleAudioRouteRecovery(reason:) (in FluidVoice)
2557 ASRService.retireAudioEngine(reason:) (in FluidVoice)
2557 -[AVAudioEngine dealloc] (in AVFAudio)
2557 _dispatch_sync_f_slow (in libdispatch.dylib)
2557 __DISPATCH_WAIT_FOR_QUEUE__ (in libdispatch.dylib)
2557 _dispatch_event_loop_wait_for_ownership (in libdispatch.dylib)
2557 _dispatch_kq_poll (in libdispatch.dylib)
2557 kevent_id (in libsystem_kernel.dylib)
Engine's internal queue (Thread B):
2557 Thread_2967515 DispatchQueue_23295: engine (serial)
...
2557 _dispatch_block_async_invoke2 (in libdispatch.dylib)
2557 invocation function for block in AVAudioEngineImpl::IOUnitConfigurationChanged() (in AVFAudio)
2557 -[NSNotificationCenter postNotificationName:object:userInfo:] (in Foundation)
2557 _CFXNotificationPost (in CoreFoundation)
2557 -[NSOperation waitUntilFinished] (in Foundation)
2557 _pthread_cond_wait (in libsystem_pthread.dylib)
2557 __psynch_cvwait (in libsystem_kernel.dylib)
All other threads were idle (run loops in mach_msg, workers in semaphore_wait/workq_kernreturn). I have the full sample output and can attach it if useful.
Activity
davemac commentedon Jul 13, 2026
This reproduced again today, roughly a day after the first occurrence, on a fresh instance of the app (same machine, same 1.6.2 build 13). I sampled the hung process before force quitting and the signature is identical down to the frame offsets:
So this is hitting at least daily in normal use for me, not a rare one-off race. Happy to attach either full sample file if useful.
altic-dev commentedon Jul 13, 2026
I have never faced it; appreciate you helping with the logs.Let me take a look at it. If not on the next update, I'll push it in the upcoming update.I made some changes to the core audio in the current one; I hope it helps.
davemac commentedon Jul 14, 2026
One correction to the reproduction conditions in my original report: I listed "sync audio devices with system enabled" as a precondition, implying it could be disabled as a mitigation. It cannot — in v1.6.2
syncAudioDevicesWithSystemis hardcoded totrue(SettingsStore.swift#L1669-L1678, "independent mode doesn't work for Bluetooth/aggregate devices"), and the Settings UI only shows the static "Audio devices are synced with macOS System Settings" notice. So thehandleDefaultInputChanged/handleDefaultOutputChangedguards can never bail out, every user is on the affected path, and there is no user-side workaround for this deadlock.It hit a third time today (third day in a row), and
~/Library/Logs/Fluid/Fluid.logpins the trigger precisely. The final entries before the app froze:Then nothing for three hours until the relaunch
[RUN]banner. On every healthy occurrence of this path the "Audio engine retired" line is immediately followed by aPrepared direct Core Audio input ...prewarm line; here that line never arrives, consistent with the process deadlocking in a device-change handler fired moments later (AirPods flip input and output in quick succession). My log shows this idle route-change path running half a dozen times a day with AirPods and a Studio Display in the mix, which matches the daily hit rate.RobinHoodO commentedon Jul 14, 2026
Independently reproduced this today (v1.6.2, macOS 26.5.1, M-series). Same signature exactly — main thread parked in
retireAudioEngine→-[AVAudioEngine dealloc]→__DISPATCH_WAIT_FOR_QUEUE__, 0% CPU, triggered by a Bluetooth headset (Shokz OpenComm2) disconnect/reconnect burst while idle. Confirms this isn't a one-off — PR #543 looks like the right fix (moving the final release off any main-thread local via a dedicated holder). Would be great to see this merged; it's been open a week with no reviews.mikesplain commentedon Jul 14, 2026
I'm running into this exact same issue as well. Hoping to see #543 merged soon as well.
Thanks for an excellent tool @altic-dev! I appreciate the pace in innovation and improvements you've been able to make every day!
Triangulum9r commentedon Jul 14, 2026
We're also hitting this on our side.
Environment: FluidVoice 1.6.4 (build 15), macOS 26.5.2 (25F84), Mac Studio (Apple M3 Ultra).
Today's incident (2026-07-14 ~13:20 PDT): While idle, AirPods Pro reconnected and the app died during the idle route-change teardown.
~/Library/Logs/Fluid/Fluid.logshows the same missing-prewarm pattern described above — the final lines before termination were:On every healthy route change in our logs,
Audio engine retiredis immediately followed byPrepared direct Core Audio input ...; here that prewarm line never arrives.Diagnostic report (
~/Library/Logs/DiagnosticReports/FluidVoice-2026-07-14-132016.ips) matches the deadlock signature from the original report:AVAudioEngineImpl::IOUnitConfigurationChanged()→-[NSOperation waitUntilFinished]-[AVAudioEngine dealloc]→__DISPATCH_WAIT_FOR_QUEUE__ASRService.registerEngineConfigurationChangeObserver()when the process abortedWe see frequent idle route changes throughout the day (Elgato Wave Link mixes, AirPods Max/Pro, iPhone Microphone), so we're squarely on the affected code path. Happy to attach the full log excerpt or
.ipsif useful.Looking forward to #543 landing — thanks for the great tool and the fast iteration.
altic-dev commentedon Jul 14, 2026
Merging this next. Did not realize its a little wide spread. So it happens when you change devices - i barely do it so never came across this.
I gotchu y'all
fix(audio): break permanent main-thread deadlock on idle route change (…
davemac commentedon Jul 26, 2026
Looks like this issue is still happening for me ...