Skip to content

Commit 9a1d48c

Browse files
authored
[Fabric-Sync] Fix deadlock when removing device (project-chip#36706)
* [Fabric-Sync] Fix deadlock when removing device * Add assertChipStackLockedByCurrentThread just in case
1 parent c4632a6 commit 9a1d48c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

examples/fabric-sync/bridge/src/BridgedDeviceManager.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,13 @@ std::optional<uint16_t> BridgedDeviceManager::AddDeviceEndpoint(std::unique_ptr<
245245

246246
int BridgedDeviceManager::RemoveDeviceEndpoint(BridgedDevice * dev)
247247
{
248+
assertChipStackLockedByCurrentThread();
249+
248250
uint8_t index = 0;
249251
while (index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
250252
{
251253
if (mDevices[index].get() == dev)
252254
{
253-
DeviceLayer::StackLock lock;
254255
// Silence complaints about unused ep when progress logging
255256
// disabled.
256257
[[maybe_unused]] EndpointId ep = emberAfClearDynamicEndpoint(index);
@@ -266,6 +267,8 @@ int BridgedDeviceManager::RemoveDeviceEndpoint(BridgedDevice * dev)
266267

267268
BridgedDevice * BridgedDeviceManager::GetDevice(chip::EndpointId endpointId) const
268269
{
270+
assertChipStackLockedByCurrentThread();
271+
269272
for (uint8_t index = 0; index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; ++index)
270273
{
271274
if (mDevices[index] && mDevices[index]->GetEndpointId() == endpointId)
@@ -304,6 +307,8 @@ std::string BridgedDeviceManager::GenerateUniqueId()
304307

305308
BridgedDevice * BridgedDeviceManager::GetDeviceByUniqueId(const std::string & id)
306309
{
310+
assertChipStackLockedByCurrentThread();
311+
307312
for (uint8_t index = 0; index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; ++index)
308313
{
309314
if (mDevices[index] && mDevices[index]->GetBridgedAttributes().uniqueId == id)
@@ -316,6 +321,8 @@ BridgedDevice * BridgedDeviceManager::GetDeviceByUniqueId(const std::string & id
316321

317322
BridgedDevice * BridgedDeviceManager::GetDeviceByScopedNodeId(chip::ScopedNodeId scopedNodeId) const
318323
{
324+
assertChipStackLockedByCurrentThread();
325+
319326
for (uint8_t index = 0; index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; ++index)
320327
{
321328
if (mDevices[index] && mDevices[index]->GetScopedNodeId() == scopedNodeId)
@@ -328,11 +335,12 @@ BridgedDevice * BridgedDeviceManager::GetDeviceByScopedNodeId(chip::ScopedNodeId
328335

329336
std::optional<uint16_t> BridgedDeviceManager::RemoveDeviceByScopedNodeId(chip::ScopedNodeId scopedNodeId)
330337
{
338+
assertChipStackLockedByCurrentThread();
339+
331340
for (uint16_t index = 0; index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; ++index)
332341
{
333342
if (mDevices[index] && mDevices[index]->GetScopedNodeId() == scopedNodeId)
334343
{
335-
DeviceLayer::StackLock lock;
336344
EndpointId ep = emberAfClearDynamicEndpoint(index);
337345
mDevices[index] = nullptr;
338346
ChipLogProgress(NotSpecified, "Removed device with Id=[%d:0x" ChipLogFormatX64 "] from dynamic endpoint %d (index=%d)",

0 commit comments

Comments
 (0)