Skip to content

RDKEMW-22339: BLE key thread spins due to fds not cleaned up properly - #264

Merged
egalla204 merged 11 commits into
developfrom
feature/RDKEMW-22339_ble-key-thread-spins
Aug 3, 2026
Merged

RDKEMW-22339: BLE key thread spins due to fds not cleaned up properly#264
egalla204 merged 11 commits into
developfrom
feature/RDKEMW-22339_ble-key-thread-spins

Conversation

@egalla204

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings July 27, 2026 18:48
@egalla204
egalla204 requested a review from a team as a code owner July 27, 2026 18:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI review requested due to automatic review settings July 28, 2026 16:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 case event would be only partially populated (even though it was memset), but the code will still call HandleKeypress, potentially generating incorrect key events. It’s safer to only process the event when read() returns exactly sizeof(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);

@klu339

klu339 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Approved for QA test

@egalla204
egalla204 merged commit c00fca8 into develop Aug 3, 2026
10 checks passed
@egalla204
egalla204 deleted the feature/RDKEMW-22339_ble-key-thread-spins branch August 3, 2026 20:42
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants