fix: make rf_mapper scan state thread-safe and harden sleep/shutdown #2213
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.
Problem
RFmapperupdates scan state from a background thread and reads it from the run loop without synchronization. This can produce inconsistent reads and race conditions.There are also two runtime reliability issues:
self.sleep(1)is called even thoughRFmapperhas nosleep()methodjoin()Related issue: #1771
Changes
threading.Lock()(scan_lock) for shared scan statescan_idx,scan_results, andscan_last_sentreads/writes with the locklogging.warnwithlogging.warningself.seen_namesself.sleep(1)withtime.sleep(1.0)self.thread.join(timeout=1.0)Validation
python3 -m py_compile src/backgrounds/plugins/rf_mapper.py