daltoniam / Starscream

Websockets in swift for iOS and OSX
Apache License 2.0
8.33k stars 1.21k forks source link

Attempted to dereference garbage pointer #801

Open tapz opened 4 years ago

tapz commented 4 years ago

Getting this crash report from my users every now and then with version 4.0.3

MyService.swift:

import Starscream

class MyService {
  var ws: WebSocket?
  fileprivate let backgroundQueue = DispatchQueue(label: "my.queue.background", qos: .background, attributes: .concurrent)
  ...
  fileprivate init() {
    self.pingTimer = DispatchSource.makeTimerSource(queue: self.backgroundQueue)
    self.pingTimer?.schedule(deadline: .now(), repeating: .seconds(20), leeway: .seconds(5))
    self.pingTimer?.setEventHandler { [weak self] in
      guard let sself = self else {
        return
      }
      sself.ws?.write(ping: Data()) // Line 91
    }
  }
}

Crash report:

OS Version: iOS 13.4.1 (17E262)

Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: BUS_NOOP at 0x00000006fa6873a0
Crashed Thread: 12

Application Specific Information:
Exception 1, Code 4201149344, Subcode 8 >
Attempted to dereference garbage pointer 0x6fa6873a0.

Thread 12 Crashed:
0   libobjc.A.dylib                 0x193be2980         objc_retain
1   libswiftDispatch.dylib          0x380c5f554         OS_dispatch_queue.async
2   Starscream                      0x104605864         WSEngine.write (WSEngine.swift:91)
3   Starscream                      0x104606b70         WSEngine
4   Starscream                      0x1045feecc         WebSocket
5   Tapani                           0x202cbc620         MyService..init (MyService.swift:91)
6   Tapani                           0x202cd5958         @callee_guaranteed
7   libdispatch.dylib               0x193b6b520         _dispatch_client_callout
8   libdispatch.dylib               0x193b45270         _dispatch_continuation_pop$VARIANT$armv81
9   libdispatch.dylib               0x193b5540c         _dispatch_source_invoke$VARIANT$armv81
10  libdispatch.dylib               0x193b45140         _dispatch_continuation_pop$VARIANT$armv81
11  libdispatch.dylib               0x193b449e4         _dispatch_async_redirect_invoke
12  libdispatch.dylib               0x193b51530         _dispatch_root_queue_drain
13  libdispatch.dylib               0x193b51ccc         _dispatch_worker_thread2
14  libsystem_pthread.dylib         0x193bbcb34         _pthread_wqthread
tapz commented 4 years ago

Another similar:

0   libswiftCore.dylib              0x37c03fa10         swift::RefCounts<T>::formWeakReference
1   libswiftCore.dylib              0x37c01b4b8         [inlined] swift_weakInit
2   libswiftCore.dylib              0x37c01b4b8         swift_weakInit
3   Starscream                      0x103f89428         WSEngine.stop (WSEngine.swift:75)
4   Starscream                      0x103f8ab1c         WSEngine
5   Starscream                      0x103f82664         WebSocket.disconnect (WebSocket.swift:139)
tapz commented 4 years ago
0   libdispatch.dylib               0x19641f3b8         _os_object_retain
1   libswiftDispatch.dylib          0x34e7f7ef0         OS_dispatch_queue.async
2   Starscream                      0x104929864         WSEngine.write (WSEngine.swift:91)
3   Starscream                      0x10492ac44         [inlined] WSEngine.write (WSEngine.swift:87)
4   Starscream                      0x10492ac44         WSEngine (<compiler-generated>:85)
5   Starscream                      0x104922e30         [inlined] WebSocket.write (WebSocket.swift:151)
6   Starscream                      0x104922e30         WebSocket (<compiler-generated>:150)
tapz commented 4 years ago
0   libobjc.A.dylib                 0x191127f90         objc_destructInstance
1   libswiftCore.dylib              0x355f630e4         [inlined] swift_deallocClassInstance
2   libswiftCore.dylib              0x355f630e4         swift_deallocClassInstance
3   libswiftCore.dylib              0x355f63008         _swift_release_dealloc
4   libswiftCore.dylib              0x355f63d5c         swift::RefCounts<T>::doDecrement<T>
5   Starscream                      0x104706a08         WSEngine.deinit
6   Starscream                      0x104706ab4         WSEngine.__deallocating_deinit
7   libswiftCore.dylib              0x355f63008         _swift_release_dealloc
8   libswiftCore.dylib              0x355f63d5c         swift::RefCounts<T>::doDecrement<T>
9   Starscream                      0x1046febec         [inlined] WebSocket.deinit
10  Starscream                      0x1046febec         WebSocket.__deallocating_deinit (WebSocket.swift:94)
11  libswiftCore.dylib              0x355f63008         _swift_release_dealloc
12  libswiftCore.dylib              0x355f63d5c         swift::RefCounts<T>::doDecrement<T>
philipyoungg commented 3 years ago

@tapz did you find the solution?