Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gen4] fixes BLE race condition while scanning #2818

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

XuGuohui
Copy link
Member

Problem

Imagine the following scenario:

  1. threadX: User app starts BLE scanning
  2. BLE event thread: User app calls BLE.stopScanning() to stop scanning in scan result callback
  3. [ threadX: BLE HAL acquires s_bleMutex ] in stopScanning() to try calling le_scan_stop() to stop scanning
  4. [ BLE event thread: acquires sBleEventMutex ] since a new scan result is notified and BLE.stopScanning() is called again, which will try acquiring s_bleMutex, suspending...
  5. threadX: continues to run and try acquiring sBleEventMutex before calling le_scan_stop(), suspending...
  6. deadlock happens

Solution

Do not notify scan results once BLE.stopScanning() is called.

Steps to Test

user/tests/wiring/ble_scanner_broadcaster

Example App

N/A

References

N/A


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@XuGuohui XuGuohui added this to the 5.9.0 milestone Aug 27, 2024
@XuGuohui XuGuohui requested a review from avtolstoy August 27, 2024 08:37
@XuGuohui XuGuohui force-pushed the fix/gen4_ble_notify_scan_result branch from 15fb8e1 to 79b7ca8 Compare August 29, 2024 13:06
@XuGuohui XuGuohui merged commit bdf3fba into develop Aug 29, 2024
13 checks passed
@XuGuohui XuGuohui deleted the fix/gen4_ble_notify_scan_result branch August 29, 2024 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants