Skip to content

EXC_BAD_ACCESS KERN_INVALID_ADDRESS crash in AsyncBluetoothLogging.logger(for:) #83

@curioustechizen

Description

@curioustechizen

(Disclaimer: I'm using a very old version of the library - 1.12.0, so this should not be a bug. Instead it should have been a Question but I don't see a Discussions section in this library so I'm asking the question here instead).

Recently we introduced a new flow in our app that checks the status of Bluetooth at a certain point in the app. Since then, I see several crashes in production with the following stack trace:

Crashed: com.apple.root.user-initiated-qos.cooperative
0  MyApp             0x581e0c static AsyncBluetoothLogging.logger(for:) + 16 (AsyncBluetoothLogging.swift:16)
1  MyApp             0x563204 CentralManager.waitUntilReady() + 60 (CentralManager.swift:60)
2  libswift_Concurrency.dylib     0x5c134 swift::runJobInEstablishedExecutorContext(swift::Job*) + 292
3  libswift_Concurrency.dylib     0x5d5c8 swift_job_runImpl(swift::Job*, swift::SerialExecutorRef) + 156
4  libdispatch.dylib              0x13db0 _dispatch_root_queue_drain + 364
5  libdispatch.dylib              0x1454c _dispatch_worker_thread2 + 156
6  libsystem_pthread.dylib        0x9d0 _pthread_wqthread + 232
7  libsystem_pthread.dylib        0xaac start_wqthread + 8

I do see this crash in testing but it is difficult to pin-point the exact steps that repro it. It seems to be related to calling waitUntilReady while the Bluetooth is turned off from the Settings app (it does not seem to occur if Bluetooth is turned off from Control Center). The code that I use looks like this where asyncBtCentralManager is an instance of CentralManager from AsyncBluetooth library.

  func getBluetoothStatus() {
      Task {
          try await asyncBtCentralManager.waitUntilReady()
          let btState = asyncBtCentralManager.getCbState()
          // Do something with btState
      }
  }

I don't expect this to be fixed in the library. But do you have any ideas on how I could work around it in my app? Should slapping a @MainActor in on the Task above be enough?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions