Skip to content

[Bugfix] Remote descriptor not found when char handles out of order#415

Merged
h2zero merged 1 commit intomasterfrom
bugfix/desciptor-not-found
Mar 29, 2026
Merged

[Bugfix] Remote descriptor not found when char handles out of order#415
h2zero merged 1 commit intomasterfrom
bugfix/desciptor-not-found

Conversation

@h2zero
Copy link
Copy Markdown
Owner

@h2zero h2zero commented Mar 29, 2026

This resolves the issue of retrieving characteristics out of handle order and then trying to subscribe or do some other fetch of a descriptor belonging to that characteristic and the search handle was limited to the handle of the next characteristic in the vector.

This ensures that the vector is sorted in ascending order based on handle values so the next characteristic in the vector will always have a higher handle value and the descriptor search will function as intended.

Fixes #395

Summary by CodeRabbit

  • Bug Fixes
    • Improved consistency of BLE remote service characteristic discovery by ensuring characteristics are now returned in a deterministic order, eliminating potential ordering inconsistencies during device communication.

This resolves the issue of retrieving characteristics out of handle order and then trying to subscribe or
do some other fetch of a descriptor belonging to that characteristic and the search handle was limited
to the handle of the next characteristic in the vector.

This ensures that the vector is sorted in ascending order based on handle values so the next characteristic
in the vector will always have a higher handle value and the desciptor serach will function as intended.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 99772dc3-7903-4b0b-9827-50a18c912a6d

📥 Commits

Reviewing files that changed from the base of the PR and between 0db2215 and 591083a.

📒 Files selected for processing (1)
  • src/NimBLERemoteService.cpp

📝 Walkthrough

Walkthrough

Arrr, this change be addin' a sort to the characteristic discovery process! After the NimBLE stack retrieves all characteristics fer a service, the code now sorts m_vChars by handle value in ascending order. This be ensurin' deterministic ordering o' the stored characteristics, which prevents descriptor lookup failures when handles be gettin' out o' sync with the service's end handle, matey! 🏴‍☠️

Changes

Cohort / File(s) Summary
Characteristic Sortin' Logic
src/NimBLERemoteService.cpp
Added #include <algorithm> and integrated std::sort call to arrange m_vChars by characteristic handle after successful discovery, ensurин' deterministic ordering fer subsequent descriptor operations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

⚓ Ye characteristics be scattered 'cross the seven seas,
But now they're sorted by their handles with such ease,
No more will descriptors fail to find their way,
For order be restored on this fine day! 🗺️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: sorting characteristics by handle to fix descriptor lookups when characteristics are retrieved out of order.
Linked Issues check ✅ Passed The code changes directly address issue #395 by sorting characteristics by handle to ensure descriptor searches use correct handle ranges regardless of retrieval order.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the descriptor lookup issue; only a header include and sorting logic were added with no extraneous modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/desciptor-not-found

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@h2zero h2zero merged commit 67fa477 into master Mar 29, 2026
66 checks passed
@h2zero h2zero deleted the bugfix/desciptor-not-found branch March 29, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error in retrieveDescriptors() during subscribe

1 participant