Skip to content

Deadlock when handling crashes #6560

@noahsmartin

Description

@noahsmartin

Platform

iOS

Environment

Production

Installed

Swift Package Manager

Version

Current

Xcode Version

All

Did it work on previous versions?

No

Steps to Reproduce

There is a deadlock when the SDK attempts to write out a crash report if any other thread holds the dyld lock. This means when a crash occurs the SDK sometimes freezes and never writes the crash report, causing crashes to be dropped.

To reproduce, run this function:

  func hammerDyldImageCount(workers: Int = 10) {
    let q = DispatchQueue(label: "test", attributes: [.concurrent, .initiallyInactive])

      for _ in 0..<workers {
        q.async {
          var checksum: UInt64 = 0
          while true {
            let count = _dyld_image_count()
            for j in 0..<count {
              let header = _dyld_get_image_header(j)
              checksum &+= UInt64(UInt(bitPattern: header))
            }
          }
        }
      }
    q.activate()
  }

And then crash the app. I did this by adding this code into the iOS-Swift sample app and pressing "Crash the app". The debugger must be disconnected when you run this.

This is the same root cause as here: #1892 (comment) and here: #5609 although in that issue I thought it was debug only. It's also the same root cause as: #4056 that specific cause was fixed (for non-debug) but the codepath is still reachable with the steps described here.
This issue: #2996 is also the same root cause but that issue doesn't classify it as a bug or note that it causes deadlock/data loss.

The cleanest solution might be to delete all symbolication from the SDK, since it's rarely safe to use or beneficial (because it requires dsyms to really work). That could be done in the upcoming major version release and if in-process symbolication needs to be added back for some reason we can take the time to do it in a single more robust way.

Expected Result

The app crash should trigger the SDK to write a payload to disk, and then the app should exit and the system crash dialog gets presented.

Actual Result

The app deadlocks and has to be force quit. It happens about 1/3 times for me.

Are you willing to submit a PR?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions