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

Fix linux BLE deadlock #26418

Merged
merged 7 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/controller/python/chip/ble/LinuxImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ extern "C" void * pychip_ble_start_scanning(PyObject * context, void * adapter,
return nullptr;
}

if (scanner->StartScan(chip::System::Clock::Milliseconds32(timeoutMs)) != CHIP_NO_ERROR)
CHIP_ERROR err = CHIP_NO_ERROR;
chip::DeviceLayer::PlatformMgr().LockChipStack();
err = scanner->StartScan(chip::System::Clock::Milliseconds32(timeoutMs));
tehampson marked this conversation as resolved.
Show resolved Hide resolved
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
if (err != CHIP_NO_ERROR)
{
return nullptr;
}
Expand Down
3 changes: 1 addition & 2 deletions src/platform/Linux/bluez/ChipDeviceScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ std::unique_ptr<ChipDeviceScanner> ChipDeviceScanner::Create(BluezAdapter1 * ada

CHIP_ERROR ChipDeviceScanner::StartScan(System::Clock::Timeout timeout)
{
assertChipStackLockedByCurrentThread();
ReturnErrorCodeIf(mIsScanning, CHIP_ERROR_INCORRECT_STATE);

mIsScanning = true; // optimistic, to allow all callbacks to check this
Expand All @@ -144,9 +145,7 @@ CHIP_ERROR ChipDeviceScanner::StartScan(System::Clock::Timeout timeout)
return CHIP_ERROR_INTERNAL;
}

DeviceLayer::PlatformMgr().LockChipStack();
CHIP_ERROR err = chip::DeviceLayer::SystemLayer().StartTimer(timeout, TimerExpiredCallback, static_cast<void *>(this));
DeviceLayer::PlatformMgr().UnlockChipStack();

if (err != CHIP_NO_ERROR)
{
Expand Down
3 changes: 3 additions & 0 deletions src/platform/Linux/bluez/ChipDeviceScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class ChipDeviceScanner
~ChipDeviceScanner();

/// Initiate a scan for devices, with the given timeout
///
/// This method must be called while in the Matter context (from the Matter event
/// loop, or while holding the Matter stack lock).
CHIP_ERROR StartScan(System::Clock::Timeout timeout);

/// Stop any currently running scan
Expand Down