RDKEMW-22339: BLE key thread spins due to fds not cleaned up properly - #264
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses an operational issue in the Control Manager (ctrlm-main) BLE key monitoring path where the BLE key monitor thread could spin at high CPU when BlueZ destroys input device nodes and stale fds aren’t cleaned up, and it refines thread-monitor behavior around DEEP_SLEEP transitions.
Changes:
- Adjusts
ctrlm_thread_monitor()to perform a final responsiveness check during the DEEP_SLEEP transition before deactivating monitoring. - Ensures BLE key monitor state is cleaned up on BLE shutdown by queueing per-device removal messages before tearing down the controller/adapter.
- Makes the BLE key monitor thread close and invalidate fds on EOF and on specific “device gone” read errors to prevent tight-loop spinning.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/ctrlm_main.cpp | Updates thread monitoring activation/deactivation logic to include a final check before going quiet in DEEP_SLEEP. |
| src/ble/ctrlm_ble_rcu_interface.cpp | Queues device removal on shutdown and hardens key-monitor fd handling (EOF + device-gone errors) to avoid CPU spin. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/ble/ctrlm_ble_rcu_interface.cpp:1707
read()can return a short positive byte count (e.g., due to signal interruption / partial read). In that caseeventwould be only partially populated (even though it was memset), but the code will still callHandleKeypress, potentially generating incorrect key events. It’s safer to only process the event whenread()returns exactlysizeof(input_event)and ignore/log short reads.
ret = read(rcu.second, (void*)&event, sizeof(event));
if (ret == 0) {
// EOF - the underlying input device node is gone.
XLOGD_WARN("Input device for RCU <%s> hit EOF, closing fd <%d>",
rcu.first.toString().c_str(), rcu.second);
Contributor
|
Approved for QA test |
klu339
approved these changes
Aug 3, 2026
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.
No description provided.