Merged
Conversation
maxstreicher-rosslight
approved these changes
Jan 20, 2026
Contributor
Repo CoveragePR Coverage53/64 changed lines covered (Lines: 82.81%, Branches: 75%) Darp.Ble🔴 Darp.Ble/Implementation/BleObserver.cs — 41/48 changed lines covered (Lines: 85.42%, Branches: 75%)...
84 ⬛ return;
85 🟨 if (_observerState is not ObserverState.Stopped)
86 🟥 throw new InvalidOperationException($"Observer is in invalid state {_observerState}");
87 ⬛
...
139 ⬛ // Best-effort only. No thread safety guarantees
140 🟨 if (_bleDevice.IsDisposing || _observerState is ObserverState.Stopping or ObserverState.Stopped)
141 🟥 return;
142 ⬛
...
176 ⬛ return;
177 🟨 if (_observerState is not ObserverState.Observing)
178 🟥 throw new InvalidOperationException($"Observer is in invalid state {_observerState}");
179 ⬛
...
185 🟩 }
186 🟥 catch (Exception e)
187 ⬛ {
188 🟥 Logger.LogObserverErrorDuringStopping(e);
189 ⬛ // In case of an error when stopping we assume we are still observing
190 ⬛ // Not ideal, but better than to wait for ever
191 🟥 _observerState = ObserverState.Observing;
192 🟥 throw;
193 ⬛ }
...🔴 Darp.Ble/Utils/Helpers.cs — 11/14 changed lines covered (Lines: 78.57%, Branches: 75%)...
10 🟩 int handlerIndex = Array.IndexOf(array, item);
11 🟨 if (handlerIndex < 0)
12 ⬛ {
13 🟥 newArray = null;
14 🟥 return false;
15 ⬛ }
...
25 🟩 newArray = new T[arraySpan.Length - 1];
26 🟨 if (handlerIndex > 0)
27 🟥 arraySpan[..handlerIndex].CopyTo(newArray);
28 🟩 if (handlerIndex < arraySpan.Length - 1)
...🔴 Darp.Ble/BleObserverExtensions.cs — 1/2 changed lines covered (Lines: 50%, Branches: n/a)...
30 ⬛ {
31 🟥 IDisposable unhook = bleObserver.OnAdvertisement(onAdvertisement: observer.OnNext);
32 ⬛
...Legend: 🟥 uncovered · 🟨 partial branch · 🟩 covered · ⬛ non-executable/blank |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Right now the BleObserver is not thread save. There are multiple issues where especially around the synchronization of start/stop and the enumeration of subscriptions. This adds regression tests and attempts to make the BLE observer thread safe
Changes
Testing
Added regression tests
Checklist