Repository navigation
Conversation
WatchPropertiesAsync returns Task<IDisposable>. Since Task is itself IDisposable, the `ret is IDisposable` check in the BlueZNet helpers stored the task as the watcher, so Dispose() disposed the task and never removed the D-Bus match. Every connect leaked a "Connected" watchdog (each disconnect was then reported once per earlier connect) and a WaitForPropertyValueAsync watcher whose TaskCompletionSource had already completed. On the next reconnect that stale watcher called SetResult again, threw out of the signal handler, and the auto-reconnect watchdog never ran: the earbuds came back in BlueZ but the app stayed disconnected until restarted. Dispose the real subscription once it is available, use TrySetResult / TrySetException so a repeated change cannot throw, and dispose the watcher on timeout as well.
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
On Linux the app often fails to reconnect after the earbuds go back in the case and come out again: BlueZ shows them connected and audio plays, but the app stays disconnected until it is restarted. The log shows the auto-reconnect never runs, only:
Cause
WatchPropertiesAsyncreturnsTask<IDisposable>. BecauseTaskis itselfIDisposable, theret is IDisposablecheck inWatchForPropertyChangeAsyncandWatchPropertyValueAsyncstores the task as the watcher, soDispose()disposes the task and never removes the D-Bus match. As a result:Connectedwatchdog, so each disconnect is reported once per earlier connect (the log showsLinux.BluetoothService: Disconnectedtwice after two connects);WaitForPropertyValueAsyncleaks a watcher whoseTaskCompletionSourcealready completed. On the next reconnect it callsSetResultagain, the exception escapes the signal handler (thecatchcallsSetException, which throws too), and the handler that would have triggeredConnectionWatcherCallbacknever runs.Change
Task<IDisposable>so disposing the watcher disposes the real subscription once it is available.TrySetResult/TrySetExceptionso a repeated property change cannot throw.Testing
Linux (Arch, BlueZ), Galaxy Buds4 Pro. Disconnect/reconnect twice in a row with
bluetoothctl, then the real case: buds in the closed case until they drop, then out. Each disconnect is now logged once,Reconnected. Attempting to auto-connect to profile...follows every reconnect, and no exception is thrown.