Crash after bluetooth earphone is disconnected

Description

Application crashes after bluetooth device is disconnected.

Steps to reproduce

Connect player (device A) to the server (device B).

Connect a bluetooth earphone/headphone to device A.

The bluetooth is selected as the default audio device.

The sound from device A can be heard from device B.

Disconnect the bluetooth earphone/headphone from device A.

AudioRelay on device A crashes.

Devices

Device A: as a player
Windows 11
AudioRelay 0.27.5

Device B: as a server
macOS Sonoma 14.6.1
AudioRelay 0.27.5

log from audioRelay:
2024-10-31 20:16:39:195 [WARN] System error: SystemErrorId(value=RTAUDIO_STREAM_STOPPED_ERROR)
2024-10-31 20:16:39:203 [ERROR] Audio output failed: com.azefsw.audioconnect.desktop.exceptions.StreamNotRunningException: The stream stopped running. The audio device changed or was removed
at ZF0.invokeSuspend(SourceFile:57)
at jUr4.resumeWith(SourceFile:5)
at Eu.run(SourceFile:163)
at Yj.run(SourceFile:19)

log from audiorelay.backend:
2024-10-31 20:16:39.621 [ERR] Socket service error
System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. —> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte buffer, Int32 offset, Int32 size)
— End of inner exception stack trace —
at System.Net.Sockets.NetworkStream.Read(Byte buffer, Int32 offset, Int32 size)
at System.IO.Stream.ReadByte()
at Google.Protobuf.ParsingPrimitives.ReadRawVarint32(Stream input)
at Google.Protobuf.MessageExtensions.MergeDelimitedFrom(IMessage message, Stream input, Boolean discardUnknownFields, ExtensionRegistry registry)
at Google.Protobuf.MessageParser1.ParseDelimitedFrom(Stream input) at AudioConnect.Ipc.IpcSocketsService.<>c__DisplayClass10_0.<ReadMessages>b__0() at AudioConnect.Rx.Observables.<>c__DisplayClass2_11.b__1(Int32 _, ICancelable cancelable)
2024-10-31 20:16:39.622 [INF] Connection lost

I have this issue too - while not a fix, I’m working around this issue by adding this autohotkey (v2) script to my startup folder (update program location if needed, and might have to resize window if the servers list doesn’t show up without scrolling)

#Requires AutoHotkey v2.0
#SingleInstance Force

SetTitleMatchMode 2
SEC_TO_MS := 1000

Loop {
	; Wait for AudioRelay to crash (crash window title is "AudioRelay.exe" instead of "AudioRelay" which makes it easier to detect)
    WinWait "AudioRelay.exe"
    WinClose "AudioRelay.exe"
    Sleep 1*SEC_TO_MS
    Run 'C:\Program Files (x86)\AudioRelay\AudioRelay.exe'

    WinWait "AudioRelay"
    WinActivate
    Sleep 2*SEC_TO_MS

    CoordMode "Mouse", "Window"
    ; Click the left-side "Player"
    Click 50, 125
	; Wait 5s for servers to load, then click the first one in the list
    Sleep 5*SEC_TO_MS
    Click 375, 800
}

This shouldn’t occur in the next version. An early access version is available from Announcements