kvm/internal
Alex P 051950f220 Fix critical deadlock when switching audio sources
Problem:
When switching audio sources (USB to HDMI or vice versa), the application
would hang indefinitely. This was caused by a deadlock between Go and C
layers:

1. Main thread calls SetAudioOutputSource() → stopOutputAudio()
2. stopOutputAudio() calls outputRelay.Stop() which waits for goroutine
3. Goroutine is blocked in ReadMessage() holding Go mutex
4. ReadMessage() calls blocking C function jetkvm_audio_read_encode()
5. C function is blocked reading from ALSA device
6. Disconnect() can't acquire Go mutex to clean up
7. Deadlock: Main thread waiting for goroutine, goroutine waiting for ALSA

Solution:
Release the Go mutex BEFORE calling blocking C functions in ReadMessage()
and WriteMessage(). The C layer has its own pthread mutex protection and
handles stop requests via atomic flags. This allows:
- Disconnect() to acquire the mutex immediately
- C layer to detect stop request and return quickly
- Goroutines to exit cleanly
- Audio source switching to work flawlessly

Fixes:
- internal/audio/cgo_source.go:ReadMessage() - Release mutex before C call
- internal/audio/cgo_source.go:WriteMessage() - Release mutex before C call

This fix eliminates the hang when switching between USB and HDMI audio
sources.
2025-11-18 01:41:46 +02:00
..
audio Fix critical deadlock when switching audio sources 2025-11-18 01:41:46 +02:00
confparser feat: refactoring network stack (#878) 2025-10-15 18:32:58 +02:00
hidrpc feat: release keyPress automatically (#796) 2025-09-18 13:35:47 +02:00
logging feat: jetkvm native in cGo 2025-09-29 14:09:30 +02:00
mdns feat: refactoring network stack (#878) 2025-10-15 18:32:58 +02:00
native Fix: improve EDID compatibility and add audio configuration options 2025-11-18 00:53:15 +02:00
network/types feat: refactoring network stack (#878) 2025-10-15 18:32:58 +02:00
sync feat: refactoring network stack (#878) 2025-10-15 18:32:58 +02:00
timesync feat: refactoring network stack (#878) 2025-10-15 18:32:58 +02:00
tzdata feat: improve custom jiggler settings and add timezone support (#742) 2025-08-24 22:54:26 +00:00
usbgadget Fix: skip redundant USB gadget reconfigurations to prevent HID disruption 2025-11-17 22:48:02 +02:00
utils fix: ensure that security-key backed SSH keys are supported (#807) 2025-09-17 12:14:45 +02:00
websecure feat(websecure): add support for ed25519 certificates (#513) 2025-05-25 11:09:58 +02:00