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

Fixes the issue that BLE.scan() might hang the device. #2220

Merged
merged 4 commits into from
Nov 20, 2020

Conversation

XuGuohui
Copy link
Member

Problem

BLE may hang the thread that calls BLE.scan() due to unexpected scanning failure. Since the BLE.scan() is a blocking API waiting until a semaphore is given on scanning timeout event, in some condition the scanning procedure never timeout or a incorrect event is delivered from SoftDevice on scanning failure, in which case the semaphore cannot be taken any more.

Solution

Introduce a timer to guard the scanning procedure. For example, if the scanning timeout is set to 5s and it starts scanning, the timer will expire after 6s to stop scanning actively. Normally BLE scanning can timeout by SoftDevice and the timer will be stopped by then.

References

#1932


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 3.0.0 milestone Oct 15, 2020
Copy link
Member

@avtolstoy avtolstoy left a comment

Choose a reason for hiding this comment

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

@XuGuohui Can we add a synthetic test for this? For example block the BLE thread or block BLE interrupt to simulate this behavior?

hal/src/nRF52840/ble_hal.cpp Outdated Show resolved Hide resolved
hal/src/nRF52840/ble_hal_impl.h Outdated Show resolved Hide resolved
@XuGuohui
Copy link
Member Author

@XuGuohui Can we add a synthetic test for this? For example block the BLE thread or block BLE interrupt to simulate this behavior?

A test is added to user/tests/wiring/ble_scanner_broadcaster/ble_scanner. And I ran it manually with success.

@XuGuohui XuGuohui merged commit fcfffca into develop Nov 20, 2020
@XuGuohui XuGuohui deleted the fix/ble_scan_hangs/ch65691 branch November 20, 2020 04:37
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