Skip to content

BLE: thread unsafe access of BLEServer::m_connectedServersMap #12538

@cpatulea

Description

@cpatulea

Board

Heltec WiFi LoRa 32 V3

Device Description

n/a - purely software issue

Hardware Configuration

N/A - purely software issue

Version

latest master (checkout manually)

Type

Bug

IDE Name

n/a

Operating System

n/a

Flash frequency

n/a

PSRAM enabled

yes

Upload speed

n/a

Description

Context: #12533

As I'm studying Arduino BLE code, I'm realizing that maybe there is a thread safety issue. Variables like BLEServer::m_connectedServersMap (

std::map<uint16_t, conn_status_t> m_connectedServersMap;
) are accessed from both the NimBLE thread (BLEServer::handleGATTServerEvent -> addPeerDevice) and the main thread (BLEServer::getPeerDevices) without synchronization. Maybe in practice in most cases this works. But technically speaking, this is a data race and in theory can cause very spooky crashes and unexpected behavior.

I see thread safety is referenced briefly in #9878 (comment).

This issue also seems present in historical NimBLE, it is not new to Arduino BLE.

FYI @lucasssvaz

cc @vidplace7

Sketch

n/a - probably difficult to reproduce

Debug Message

n/a

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Labels

Area: BLEIssues related to BLE

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions