Skip to content

Commit

Permalink
Cleanup dangling CommissioneedeviceProxy object on CASE session (#15902)
Browse files Browse the repository at this point in the history
establishment failure

This cleans up the dangling CommissioneeDeviceProxy object that is
usually cleaned up in case of successful commissioning in
OnDeviceConnectedFn (i.e successful CASE session establishment upon
completion of commissioning).

Consequently, failure to establish CASE should do the same *if and only
if* the device that we failed to establish CASE with matches the device
being commissioned.

Tests:
- Ensured we hit a VerifyOrDie error due to an open EC if CASE failed to
  establish, and then ensured that didn't manifest again with these
  changes.
  • Loading branch information
mrjerryjohns authored and pull[bot] committed Mar 22, 2022
1 parent 045b1d3 commit 1910609
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1501,12 +1501,23 @@ void DeviceCommissioner::OnDeviceConnectionFailureFn(void * context, PeerId peer
{
// CASE session establishment failed.
DeviceCommissioner * commissioner = static_cast<DeviceCommissioner *>(context);

ChipLogProgress(Controller, "Device connection failed. Error %s", ErrorStr(error));
VerifyOrReturn(commissioner != nullptr,
ChipLogProgress(Controller, "Device connection failure callback with null context. Ignoring"));
VerifyOrReturn(commissioner->mPairingDelegate != nullptr,
ChipLogProgress(Controller, "Device connection failure callback with null pairing delegate. Ignoring"));

//
// If a device is being commissioned currently and it is the very same device that we just failed to establish CASE with,
// we need to clean it up to prevent a dangling CommissioneeDeviceProxy object.
//
if (commissioner->mDeviceBeingCommissioned != nullptr && commissioner->mDeviceBeingCommissioned->GetPeerId() == peerId)
{
commissioner->ReleaseCommissioneeDevice(commissioner->mDeviceBeingCommissioned);
commissioner->mDeviceBeingCommissioned = nullptr;
}

commissioner->mCASESessionManager->ReleaseSession(peerId);
if (commissioner->mCommissioningStage == CommissioningStage::kFindOperational &&
commissioner->mCommissioningDelegate != nullptr)
Expand Down

0 comments on commit 1910609

Please sign in to comment.