Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db32dc8a authored by Chris Manton's avatar Chris Manton
Browse files

Race condition with channel closure

Bug: 146086425
Test: Opp does not fail at this point
Change-Id: I5ef6e1a44c02c8d2804a47809c9cee157ec41fe0
parent d4770583
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -312,10 +312,17 @@ bool bluetooth::legacy::shim::L2cap::SetCallbacks(
  bluetooth::shim::GetL2cap()->SetConnectionClosedCallback(
      cid, [this](uint16_t cid, int error_code) {
        LOG_DEBUG(LOG_TAG, "OnChannel closed callback cid:%hd", cid);
        CHECK(cid_to_callback_map_.find(cid) != cid_to_callback_map_.end());
        if (cid_to_callback_map_.find(cid) != cid_to_callback_map_.end()) {
          cid_to_callback_map_[cid]->pL2CA_DisconnectInd_Cb(
              cid, kDisconnectResponseRequired);
          cid_to_callback_map_.erase(cid);
        } else if (cid_closing_set_.count(cid) == 1) {
          cid_closing_set_.erase(cid);
        } else {
          LOG_WARN(LOG_TAG, "%s Unexpected channel closure cid:%hd", __func__,
                   cid);
        }
        CHECK(cid_to_psm_map_.find(cid) != cid_to_psm_map_.end());
        cid_to_psm_map_.erase(cid);
      });
  return true;
@@ -369,8 +376,10 @@ bool bluetooth::legacy::shim::L2cap::ConfigResponse(

bool bluetooth::legacy::shim::L2cap::DisconnectRequest(uint16_t cid) {
  CHECK(ConnectionExists(cid));
  cid_to_callback_map_.erase(cid);
  LOG_DEBUG(LOG_TAG, "%s cid:%hu", __func__, cid);
  bluetooth::shim::GetL2cap()->CloseConnection(cid);
  cid_to_callback_map_.erase(cid);
  cid_closing_set_.insert(cid);
  return true;
}

+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#pragma once

#include <cstdint>
#include <set>
#include <unordered_map>

#include "stack/include/l2c_api.h"
@@ -103,6 +104,8 @@ class L2cap {
  std::unordered_map<uint16_t,
                     std::function<void(std::function<void(uint16_t c)>)>>
      cid_to_postable_map_;
  std::set<uint16_t> cid_closing_set_;

  std::unordered_map<uint16_t, uint16_t> cid_to_psm_map_;
  std::unordered_map<uint16_t, uint16_t> client_psm_to_real_psm_map_;
  std::unordered_map<uint16_t, const tL2CAP_APPL_INFO*> cid_to_callback_map_;