Open RoeeNadam opened 11 months ago
Hi, it's still crashing sometimes in my app. What more information can I provide to help you understand how to fix it?
I still see a lot of threads being created in the background but I'm not reproducing it anymore when I test it. How are you calling start? Is it on the main thread or via another context?
Can you provide the output of the debugger command 'bt all' ?
you can see in this video the crash flow. https://youtu.be/6meD0aMVjVw
why used with "try?" and not "try catch" ?
Using try catch
will not stop the crash from happening because there is a pointer being dereferenced to an invalid location in memory. Somehow there is a fundamental misuse of the pinger because there should not be more than one background thread running at any one time. Can you guarantee that you are calling stopPinging
before calling start
again?
I always call 'stop' before I made a 'start'.
That looks great but still doesn't explain the multiple threads being started. How is your Pinger.start()
getting called? Is it from a system callback like application delegate or notification?
it called from :
public func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) { }
Not all the time, only if I get something that tells me to start to ping.
I'm still not 100% sure what is happening but I've made a change that will now force the background thread to exit on ping stop. Give it a try and let me know if you are still seeing the crash in your app.
Hi, it's crashing again but in another place
Try setting the pinglet
property to nil
in the Pinger.stop()
function and see if the crash goes away. If it does this points to a hidden retain cycle somewhere.
Okay, I set the 'pinglet' property to nil in the Pinger.stop() method and will let you know if something changes. Thanks."
its still crash
Crashed: Socket2Me internal utility
0 libobjc.A.dylib 0x2e5c objc_retain_x0 + 16
1 libobjc.A.dylib 0x2e5c objc_retain + 16
2 Saverone 0x18640c closure #1 in Socket2Me.send(data:) + 216 (Socket2Me.swift:216)
3 Saverone 0x186588 thunk for @escaping @callee_guaranteed @Sendable () -> () + 4380370312 (
Can you describe how you are using (initing/object lifecycle) the pinglet object? Are you using any of the callbacks or publishers to get notified when pings come in? I cannot tell from the code that you sent but it looks like they're not being used? I've tried testing with/without callbacks in various scenarios and I'm not able to reproduce this issue yet and I've not gotten any crash reports for my app PingPoint. I want to make sure that it can work for your use case.
I'd consider going back to using the serial queue instead of the global() queue from your example code and see if that has any effect on the crashing.
let serial queue = DispatchQueue (label: "Pinger serial queue", qos: .background)
If it does then I'll need to put some code in to ensure that we're only using the user designated queue in a serialized way.
I went ahead and added that change to 0add1ae2. Try using the latest commits and let me know if that fixes your crash.
Hi Kevin, According to the issue in GitHub, I have added this crash. If you need more details, let me know.
If you need any further assistance, feel free to ask! @.**@. From: Kevin Ross @.> Date: Monday, 3 June 2024 at 19:53 To: CocoaBeans/Pinglet @.> Cc: Roee Nadam @.>, Comment @.> Subject: Re: [CocoaBeans/Pinglet] Crash - Socket2Me._openNetworkSocket() EXC_BAD_ACCESS (KERN_INVALID_ADDRESS) (Issue #2)
I went ahead and added that change to 0add1ae2https://github.com/CocoaBeans/Pinglet/commit/0add1ae2e745db74496df34d9a5e47a0aa23ff6e. Try using the latest commits and let me know if that fixes your crash.
— Reply to this email directly, view it on GitHubhttps://github.com/CocoaBeans/Pinglet/issues/2#issuecomment-2145694310, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BGYKJ5DXKSKGPW3GAPYCJBTZFSNRZAVCNFSM6AAAAAA5BMAI3KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBVGY4TIMZRGA. You are receiving this because you commented.Message ID: @.***>
com.apple.main-thread 0 libsystem_kernel.dylib 0x1808 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x5008 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x4f20 mach_msg_overwrite + 436 3 libsystem_kernel.dylib 0x4d60 mach_msg + 24 4 CoreFoundation 0x53f5c CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x53600 CFRunLoopRun + 1208 6 CoreFoundation 0x52cd8 CFRunLoopRunSpecific + 608 7 GraphicsServices 0x11a8 GSEventRunModal + 164 8 UIKitCore 0x40a90c -[UIApplication _run] + 888 9 UIKitCore 0x4be9d0 UIApplicationMain + 340 10 Saverone 0x115974 main + 23 (AppDelegate.swift:23) 11 ??? 0x1beca1e4c (Missing)
Crashed: Pinglet internal
0 libobjc.A.dylib 0x1b60 objc_release_x0 + 16
1 libobjc.A.dylib 0x1b60 objc_release + 16
2 Saverone 0x1807b4 Pinglet.sendPing(request:) + 359 (Pinglet.swift:359)
3 Saverone 0x180b14 closure #1 in Pinglet.sendPing() + 370 (Pinglet.swift:370)
4 Saverone 0x17cf3c thunk for @escaping @callee_guaranteed @Sendable () -> () + 4373892924 (
com.apple.uikit.eventfetch-thread 0 libsystem_kernel.dylib 0x1808 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x5008 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x4f20 mach_msg_overwrite + 436 3 libsystem_kernel.dylib 0x4d60 mach_msg + 24 4 CoreFoundation 0x53f5c CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x53600 CFRunLoopRun + 1208 6 CoreFoundation 0x52cd8 CFRunLoopRunSpecific + 608 7 Foundation 0xc7e4c -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212 8 Foundation 0xc7c9c -[NSRunLoop(NSRunLoop) runUntilDate:] + 64 9 UIKitCore 0x41e640 -[UIEventFetcher threadMain] + 420 10 Foundation 0xde718 NSThreadstart__ + 732 11 libsystem_pthread.dylib 0x606c _pthread_start + 136 12 libsystem_pthread.dylib 0x10d8 thread_start + 8
Thread 0 libsystem_kernel.dylib 0x1590 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x4980 _pthread_wqthread + 364 2 libsystem_pthread.dylib 0x10cc start_wqthread + 8
com.google.firebase.crashlytics.MachExceptionServer 0 Saverone 0x1c2f14 FIRCLSProcessRecordAllThreads + 393 (FIRCLSProcess.c:393) 1 Saverone 0x1c32f4 FIRCLSProcessRecordAllThreads + 424 (FIRCLSProcess.c:424) 2 Saverone 0x1d14c8 FIRCLSHandler + 34 (FIRCLSHandler.m:34) 3 Saverone 0x1d1ccc FIRCLSMachExceptionServer + 521 (FIRCLSMachException.c:521) 4 libsystem_pthread.dylib 0x606c _pthread_start + 136 5 libsystem_pthread.dylib 0x10d8 thread_start + 8
com.apple.NSURLConnectionLoader 0 libsystem_kernel.dylib 0x1808 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x5008 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x4f20 mach_msg_overwrite + 436 3 libsystem_kernel.dylib 0x4d60 mach_msg + 24 4 CoreFoundation 0x53f5c CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x53600 CFRunLoopRun + 1208 6 CoreFoundation 0x52cd8 CFRunLoopRunSpecific + 608 7 CFNetwork 0xfdc90 _CFHostIsDomainTopLevel + 108176 8 Foundation 0xde718 NSThreadstart__ + 732 9 libsystem_pthread.dylib 0x606c _pthread_start + 136 10 libsystem_pthread.dylib 0x10d8 thread_start + 8
com.apple.CoreMotion.MotionThread 0 libsystem_kernel.dylib 0x1808 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x5008 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x4f20 mach_msg_overwrite + 436 3 libsystem_kernel.dylib 0x4d60 mach_msg + 24 4 CoreFoundation 0x53f5c CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x53600 CFRunLoopRun + 1208 6 CoreFoundation 0x52cd8 CFRunLoopRunSpecific + 608 7 CoreFoundation 0xc0f04 CFRunLoopRun + 64 8 CoreMotion 0x10210 (Missing UUID e4a6f107b302327ca121c9bebacca8f4) 9 libsystem_pthread.dylib 0x606c _pthread_start + 136 10 libsystem_pthread.dylib 0x10d8 thread_start + 8
com.apple.CFSocket.private 0 libsystem_kernel.dylib 0x9474 select$DARWIN_EXTSN + 8 1 libsystem_kernel.dylib 0x9474 select + 8 2 CoreFoundation 0xbeb7c CFSocketManager + 640 3 libsystem_pthread.dylib 0x606c _pthread_start + 136 4 libsystem_pthread.dylib 0x10d8 thread_start + 8
Thread 0 libsystem_kernel.dylib 0x1590 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x4980 _pthread_wqthread + 364 2 libsystem_pthread.dylib 0x10cc start_wqthread + 8
Socket2Me internal utility
0 libobjc.A.dylib 0x1b60 objc_release_x0 + 16
1 libobjc.A.dylib 0x1b60 objc_release + 16
2 Saverone 0x186b9c type metadata accessor for Socket2Me + 4373932956 (
com.apple.main-thread 0 libsystem_kernel.dylib 0x1808 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x5008 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x4f20 mach_msg_overwrite + 436 3 libsystem_kernel.dylib 0x4d60 mach_msg + 24 4 CoreFoundation 0x53f5c CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x53600 CFRunLoopRun + 1208 6 CoreFoundation 0x52cd8 CFRunLoopRunSpecific + 608 7 GraphicsServices 0x11a8 GSEventRunModal + 164 8 UIKitCore 0x40a90c -[UIApplication _run] + 888 9 UIKitCore 0x4be9d0 UIApplicationMain + 340 10 Saverone 0x115974 main + 23 (AppDelegate.swift:23) 11 ??? 0x1bcb09e4c (Missing)
com.apple.uikit.eventfetch-thread 0 libsystem_kernel.dylib 0x1808 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x5008 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x4f20 mach_msg_overwrite + 436 3 libsystem_kernel.dylib 0x4d60 mach_msg + 24 4 CoreFoundation 0x53f5c CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x53600 CFRunLoopRun + 1208 6 CoreFoundation 0x52cd8 CFRunLoopRunSpecific + 608 7 Foundation 0xc7e4c -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212 8 Foundation 0xc7c9c -[NSRunLoop(NSRunLoop) runUntilDate:] + 64 9 UIKitCore 0x41e640 -[UIEventFetcher threadMain] + 420 10 Foundation 0xde718 NSThreadstart__ + 732 11 libsystem_pthread.dylib 0x606c _pthread_start + 136 12 libsystem_pthread.dylib 0x10d8 thread_start + 8
com.google.firebase.crashlytics.MachExceptionServer 0 Saverone 0x1c2f14 FIRCLSProcessRecordAllThreads + 393 (FIRCLSProcess.c:393) 1 Saverone 0x1c32f4 FIRCLSProcessRecordAllThreads + 424 (FIRCLSProcess.c:424) 2 Saverone 0x1d14c8 FIRCLSHandler + 34 (FIRCLSHandler.m:34) 3 Saverone 0x1d1ccc FIRCLSMachExceptionServer + 521 (FIRCLSMachException.c:521) 4 libsystem_pthread.dylib 0x606c _pthread_start + 136 5 libsystem_pthread.dylib 0x10d8 thread_start + 8
com.apple.NSURLConnectionLoader 0 libsystem_kernel.dylib 0x1808 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x5008 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x4f20 mach_msg_overwrite + 436 3 libsystem_kernel.dylib 0x4d60 mach_msg + 24 4 CoreFoundation 0x53f5c CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x53600 CFRunLoopRun + 1208 6 CoreFoundation 0x52cd8 CFRunLoopRunSpecific + 608 7 CFNetwork 0xfdc90 _CFHostIsDomainTopLevel + 108176 8 Foundation 0xde718 NSThreadstart__ + 732 9 libsystem_pthread.dylib 0x606c _pthread_start + 136 10 libsystem_pthread.dylib 0x10d8 thread_start + 8
com.apple.CoreMotion.MotionThread 0 libsystem_kernel.dylib 0x1808 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x5008 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x4f20 mach_msg_overwrite + 436 3 libsystem_kernel.dylib 0x4d60 mach_msg + 24 4 CoreFoundation 0x53f5c CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x53600 CFRunLoopRun + 1208 6 CoreFoundation 0x52cd8 CFRunLoopRunSpecific + 608 7 CoreFoundation 0xc0f04 CFRunLoopRun + 64 8 CoreMotion 0x10210 (Missing UUID e4a6f107b302327ca121c9bebacca8f4) 9 libsystem_pthread.dylib 0x606c _pthread_start + 136 10 libsystem_pthread.dylib 0x10d8 thread_start + 8
com.apple.CFSocket.private 0 libsystem_kernel.dylib 0x9474 select$DARWIN_EXTSN + 8 1 libsystem_kernel.dylib 0x9474 select + 8 2 CoreFoundation 0xbeb7c CFSocketManager + 640 3 libsystem_pthread.dylib 0x606c _pthread_start + 136 4 libsystem_pthread.dylib 0x10d8 thread_start + 8
Thread 0 libsystem_kernel.dylib 0x1590 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x4980 _pthread_wqthread + 364 2 libsystem_pthread.dylib 0x10cc start_wqthread + 8
Thread 0 libsystem_kernel.dylib 0x1590 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x4980 _pthread_wqthread + 364 2 libsystem_pthread.dylib 0x10cc start_wqthread + 8
Crashed: Socket2Me internal utility
0 libobjc.A.dylib 0x3020 objc_msgSend + 32
1 Saverone 0x18640c closure #1 in Socket2Me.send(data:) + 216 (Socket2Me.swift:216)
2 Saverone 0x186588 thunk for @escaping @callee_guaranteed @Sendable () -> () + 4341507464 (
Thread 0 libsystem_kernel.dylib 0x1590 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x4980 _pthread_wqthread + 364 2 libsystem_pthread.dylib 0x10cc start_wqthread + 8
Thread 0 libsystem_kernel.dylib 0x1590 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x4980 _pthread_wqthread + 364 2 libsystem_pthread.dylib 0x10cc start_wqthread + 8
Thank you for the detailed crash report! I think I might have fixed it by forcing a copy of the data read from the socket before passing it to the callback. Let me know if this change appears to fix the crash.
OK, great. But why do I get v1.0.3 when updating with Xcode SPM?
I hadn't made a new release for this code change until I had verification that it fixed your issue but I went ahead and tagged the release so now it should display in Xcode as v1.0.5 when updated.
OK, I see that you uploaded the 1.0.5 release. I'll let you know if something happens. Thanks for the quick reply.
on 1.0.5 the app crash.
Hi I've got a few questions to help debug and reproduce what is going on:
Pinger.start()
method on the main thread? Pinglet
or Socket2Me
symbols in it?I have a few more defensive changes on the way but I want to see if I can reproduce it to guarantee that the problem is fixed.
Hi,
1) Pinger - try? pinglet?.startPinging() - This is the main thread.
2) Pinger - ping init PingConfiguration(interval: 0.2, queue:
its still happend for me, in the foreground after 1 hour of pinging.
Socket2Me._openNetworkSocket() EXC_BAD_ACCESS (KERN_INVALID_ADDRESS)
Crashed: Thread 0 CoreFoundation 0x81968 _CFGetNonObjCTypeID + 92 1 CoreFoundation 0xd44ac CFSocketCreateRunLoopSource + 76 2 Saverone 0x13505c Socket2Me._openNetworkSocket() + 148 (Socket2Me.swift:148) 3 Saverone 0x134dc4 @objc Socket2Me.createSocketDetached() + 75 (Socket2Me.swift:75) 4 Foundation 0x5b808 NSThreadstart__ + 716 5 libsystem_pthread.dylib 0x16cc _pthread_start + 148 6 libsystem_pthread.dylib 0xba4 thread_start + 8