apollo-ios: Crash on com.apollographql.websocket on _inputStreamCallbackFunc

Summary

Crashlytics is reporting a very rare but consistent crash on the com.apollograph.websocket queue.

Crashed: com.apollographql.websocket
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000f9d3993a0
0 libobjc.A.dylib objc_retain + 16
1 libobjc.A.dylib objc_retain_x0 + 16
2 CoreFoundation _inputStreamCallbackFunc + 60
3 CoreFoundation _signalEventSync + 216
4 CoreFoundation ___signalEventQueue_block_invoke + 28
5 libdispatch.dylib _dispatch_call_block_and_release + 32

The app is a mix of 60% foreground and 40% background.

Version

1.9.2

Steps to reproduce the behavior

Unfortunately I only have crash logs

Logs

No response

Anything else?

My hunch is that it’s the FoundationStream teardown sequence:

 func cleanup() {
    if let stream = inputStream {
      stream.delegate = nil
      CFReadStreamSetDispatchQueue(stream, nil)
      stream.close()
    }

stream.delegate is an unowned(unsafe) var.

There are several codepaths where cleanup is not called on com.apollographql.websocket. When this happens, delegate can be set to nil as the CFReadStream is attempting to invoke a callback on the deallocated delegate.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 28 (18 by maintainers)

Most upvoted comments

This is still the number one crash for our app by a large margin. I can’t reproduce it in the debugger, but I have experienced it occasionally on my device in the wild.

This morning I found a potentially related discussion on the Apple Developer forums. The stack traces are very similar to what I’m seeing in Sentry & Xcode Organizer. https://forums.developer.apple.com/forums/thread/769191

Same here Screenshot 2024-11-07 at 23 52 42

I finally caught this crash in action. Not sure if this is helpful or not: Screenshot 2024-10-30 at 2 10 05 PM