NordicSemiconductor / IOS-CoreBluetooth-Mock

Mocking library for CoreBluetooth framework.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deadlock

DrAma999 opened this issue · comments

I've found a potential deadlock while trying to simulate a write without response. If I create a CBCentralManager mock that uses the main queue, the code will crash trying to dispatch synchronously on main. CBMCentralManagerMock.swift about line 1105 method

public func writeValue(_ data: Data,
                           for characteristic: CBMCharacteristic,
                           type: CBMCharacteristicWriteType)

Here

else {
            queue.sync { //<--Here
                guard availableWriteWithoutResponseBuffer > 0 else {
                    return
                }
                availableWriteWithoutResponseBuffer -= 1
                _canSendWriteWithoutResponse = false
            }

Could you prepare a PR with a fix, please?

Sure, I'll do in the weekend