Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash CompositeEventMonitor #3635

Open
1 task
ariefnurputranto opened this issue Jul 29, 2022 · 8 comments
Open
1 task

Crash CompositeEventMonitor #3635

ariefnurputranto opened this issue Jul 29, 2022 · 8 comments
Assignees

Comments

@ariefnurputranto
Copy link

ariefnurputranto commented Jul 29, 2022

ℹ Please fill out this template when filing an issue.
All lines beginning with an ℹ symbol instruct you with what info we expect. You can delete those lines once you've filled in the info.

Per our *CONTRIBUTING guidelines, we use GitHub for
bugs and feature requests, not general support. Other issues should be opened on Stack Overflow with the tag alamofire.

Please remove this line and everything above it before submitting.

What did you do?

We update using alamofire 5.4.4 or version 5.6.1

What did you expect to happen?

Not crash

What happened instead?

to many crash in CompositeEventMonitor

Screen Shot 2
![image (1)](https://user-images.githubusercontent.com/12388348/181690632-d0f41ead-2911-4102-8c66-0f6834a8eef6.png)
022-07-29 at 09 58 28

image (1)

Alamofire Environment

**Alamofire Version: 5.4.4 or version 5.6.1
Dependency Manager:
**Xcode Version:13.4.1
Swift Version:
Platform(s) Running Alamofire:
macOS Version Running Xcode:

@patwhitehead1
Copy link

I'm getting the same thing but I'm unable to recreate it. Were you able to figure this one out?

@jshier
Copy link
Contributor

jshier commented Sep 29, 2022

It really seems like some sort of underlying Swift issue. Building with the latest Xcode may make it go away, or, if you aren't using the Notifications that are enabled by default, you can disable EventMonitors entirely by passing an empty array when you create your Session.

Session(..., eventMonitors: [])

This will ensure that the CompositeEventMonitor doesn't end up doing anything at runtime and should hopefully avoid the crash.

@ejensen
Copy link
Contributor

ejensen commented Feb 5, 2023

It really seems like some sort of underlying Swift issue. Building with the latest Xcode may make it go away, or, if you aren't using the Notifications that are enabled by default, you can disable EventMonitors entirely by passing an empty array when you create your Session.

Session(..., eventMonitors: [])

This will ensure that the CompositeEventMonitor doesn't end up doing anything at runtime and should hopefully avoid the crash.

@jshier I'm witnessing a similar crash in the CompositeEventMonitor's iteration of monitors. The app is specifying an empty event monitors array (Session(..., eventMonitors: [])) yet an a CompositeEventMonitor is still created with the defaultEventMonitors (AlamofireNotifications). There currently is no way to avoid making the CompositeEventMonitor and AlamofireNotifications in order to avoid the crash. Would it be possible to make the default eventMonitors parameter value be defaultEventMonitors instead of always prepending the defaultEventMonitors to the supplied eventMonitors array? That would allow callers to prevent initializing event monitors they do not intend on using.

EventMonitor CallStack

@jshier
Copy link
Contributor

jshier commented Feb 6, 2023

@ejensen Can you post the textual crash log that Crashlytics has? At least the call stack of the crashing thread would be helpful.

But you're right, I misremembered the eventMonitors workaround. I've pushed a branch, bug/eventmonitor-default-value, which deprecates the instance defaultEventMonitors and creates a static version that can be used as the default in the init. Give it a look.

@jshier jshier self-assigned this Feb 6, 2023
@ejensen
Copy link
Contributor

ejensen commented Feb 6, 2023

@ejensen Can you post the textual crash log that Crashlytics has? At least the call stack of the crashing thread would be helpful.

Stack Trace
Crashed: com.apple.main-thread
0  libswiftCore.dylib             0x39c40c _swift_release_dealloc + 32
1  Frame.io                       0x943f60 protocol witness for EventMonitor.request<A>(_:didParseResponse:) in conformance AlamofireNotifications + 4308598624 (<compiler-generated>:4308598624)
2  libswiftCore.dylib             0x39c424 _swift_release_dealloc + 56
3  Frame.io                       0x944f38 outlined init with copy of EventMonitor + 4308602680 (<compiler-generated>:4308602680)
4  libswiftCore.dylib             0x39c424 _swift_release_dealloc + 56
5  libsystem_blocks.dylib         0x1804 _Block_release + 192
6  libdispatch.dylib              0x3a30 _dispatch_client_callout + 20
7  libdispatch.dylib              0x11f48 _dispatch_main_queue_drain + 928
8  libdispatch.dylib              0x11b98 _dispatch_main_queue_callback_4CF + 44
9  CoreFoundation                 0x51800 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
10 CoreFoundation                 0xb704 __CFRunLoopRun + 2532
11 CoreFoundation                 0x1ebc8 CFRunLoopRunSpecific + 600
12 GraphicsServices               0x1374 GSEventRunModal + 164
13 UIKitCore                      0x514b58 -[UIApplication _run] + 1100
14 UIKitCore                      0x296090 UIApplicationMain + 364
15 Frame.io                       0x77c0 main + 18 (AppDelegate.swift:18)

Thread
0  libsystem_kernel.dylib         0x1a74 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1108 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xe5c start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x1a74 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1108 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xe5c start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x1a74 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1108 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xe5c start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x1a74 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1108 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xe5c start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x1a74 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1108 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xe5c start_wqthread + 8

com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0x14a0 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1ae4 mach_msg + 76
2  CoreFoundation                 0x6d30 __CFRunLoopServiceMachPort + 372
3  CoreFoundation                 0xb1bc __CFRunLoopRun + 1180
4  CoreFoundation                 0x1ebc8 CFRunLoopRunSpecific + 600
5  Foundation                     0x19444 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 236
6  Foundation                     0x5ae0c -[NSRunLoop(NSRunLoop) runUntilDate:] + 92
7  UIKitCore                      0x48ecc4 -[UIEventFetcher threadMain] + 524
8  Foundation                     0x6941c __NSThread__start__ + 808
9  libsystem_pthread.dylib        0x19ac _pthread_start + 148
10 libsystem_pthread.dylib        0xe68 thread_start + 8

Thread
0  libsystem_kernel.dylib         0x1a74 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1108 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xe5c start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x1a74 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1108 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xe5c start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x1a74 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1108 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xe5c start_wqthread + 8

com.google.firebase.crashlytics.MachExceptionServer
0  Frame.io                       0xb61c1c FIRCLSProcessRecordAllThreads + 393 (FIRCLSProcess.c:393)
1  Frame.io                       0xb61ffc FIRCLSProcessRecordAllThreads + 424 (FIRCLSProcess.c:424)
2  Frame.io                       0xb6f4e8 FIRCLSHandler + 34 (FIRCLSHandler.m:34)
3  Frame.io                       0xb6fce4 FIRCLSMachExceptionServer + 521 (FIRCLSMachException.c:521)
4  libsystem_pthread.dylib        0x19ac _pthread_start + 148
5  libsystem_pthread.dylib        0xe68 thread_start + 8

AVAudioSession Notify Thread
0  libsystem_kernel.dylib         0x14a0 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1ae4 mach_msg + 76
2  CoreFoundation                 0x6d30 __CFRunLoopServiceMachPort + 372
3  CoreFoundation                 0xb1bc __CFRunLoopRun + 1180
4  CoreFoundation                 0x1ebc8 CFRunLoopRunSpecific + 600
5  AudioSession                   0x6f04 CADeprecated::GenericRunLoopThread::Entry(void*) + 164
6  AudioSession                   0x108f0 CADeprecated::CAPThread::Entry(CADeprecated::CAPThread*) + 92
7  libsystem_pthread.dylib        0x19ac _pthread_start + 148
8  libsystem_pthread.dylib        0xe68 thread_start + 8

com.apple.NSURLConnectionLoader
0  libsystem_kernel.dylib         0x14a0 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1ae4 mach_msg + 76
2  CoreFoundation                 0x6d30 __CFRunLoopServiceMachPort + 372
3  CoreFoundation                 0xb1bc __CFRunLoopRun + 1180
4  CoreFoundation                 0x1ebc8 CFRunLoopRunSpecific + 600
5  CFNetwork                      0x2781dc _CFURLStorageSessionDisableCache + 60032
6  Foundation                     0x6941c __NSThread__start__ + 808
7  libsystem_pthread.dylib        0x19ac _pthread_start + 148
8  libsystem_pthread.dylib        0xe68 thread_start + 8

com.apple.coremedia.rootQueue.47
0  libsystem_kernel.dylib         0x14f4 semaphore_timedwait_trap + 8
1  libdispatch.dylib              0x4048 _dispatch_sema4_timedwait + 64
2  libdispatch.dylib              0x463c _dispatch_semaphore_wait_slow + 76
3  libdispatch.dylib              0x14f38 _dispatch_worker_thread + 312
4  libsystem_pthread.dylib        0x19ac _pthread_start + 148
5  libsystem_pthread.dylib        0xe68 thread_start + 8

com.apple.coremedia.rootQueue.47
0  libsystem_kernel.dylib         0x14f4 semaphore_timedwait_trap + 8
1  libdispatch.dylib              0x4048 _dispatch_sema4_timedwait + 64
2  libdispatch.dylib              0x463c _dispatch_semaphore_wait_slow + 76
3  libdispatch.dylib              0x14f38 _dispatch_worker_thread + 312
4  libsystem_pthread.dylib        0x19ac _pthread_start + 148
5  libsystem_pthread.dylib        0xe68 thread_start + 8

com.apple.coremedia.rootQueue.47
0  libsystem_kernel.dylib         0x14f4 semaphore_timedwait_trap + 8
1  libdispatch.dylib              0x4048 _dispatch_sema4_timedwait + 64
2  libdispatch.dylib              0x463c _dispatch_semaphore_wait_slow + 76
3  libdispatch.dylib              0x14f38 _dispatch_worker_thread + 312
4  libsystem_pthread.dylib        0x19ac _pthread_start + 148
5  libsystem_pthread.dylib        0xe68 thread_start + 8

But you're right, I misremembered the eventMonitors workaround. I've pushed a branch, bug/eventmonitor-default-value, which deprecates the instance defaultEventMonitors and creates a static version that can be used as the default in the init. Give it a look.

The bug/eventmonitor-default-value looks good to me. It would require some upgrade notes though since it does change the default behavior for integrators that do supply a non-default value for the eventMonitors parameter.

@jshier
Copy link
Contributor

jshier commented Feb 7, 2023

Yeah, I'm not sure I can ship such a change. Ultimately the issue is I don't understand the cause of the crash. Iteration of a constant array should't cause any issues, even from multiple queues, as there's no mutation. All I can think is that the values passed into the EventMonitor don't like be dispatched between queues. I'll have to take another look.

@klaas
Copy link

klaas commented Mar 3, 2023

I have another problem that also needs to avoid the AlamofireNotifications event monitor:

I'm using Alamofire in a little corner of a larger Vapor project (using AsyncHTTPClient in most cases...). Since Vapor blocks the main thread I try to avoid Alamofire scheduling/dispatching anything on it. Currently, there is no way to disable the AlamofireNotifications event monitor, which results in dispatching blocks on the main queue. It seems that it is not possible to set the queue in this situation.

AlamofireNotifications uses the default queue provided by the EventMonitor protocol:

extension EventMonitor {
/// The default queue on which `CompositeEventMonitor`s will call the `EventMonitor` methods. `.main` by default.
public var queue: DispatchQueue { .main }

It would be helpful if the AlamofireNotifications event monitor could be disabled or not be added at all.

@alfredcc
Copy link

alfredcc commented Jan 11, 2024

We also encountered this crash, but the stack information is indeed limited.

image

Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x9898 lookUpImpOrForward + 88
1 libobjc.A.dylib 0x4cc4 _objc_msgSend_uncached + 68
2 libobjc.A.dylib 0x7bbc objc_object::sidetable_release(bool, bool) + 292
3 CFNetwork 0x2080e0 _CFHTTPServerResponseEnqueue + 22976
4 CoreFoundation 0xc310 _CFRelease + 292
5 CFNetwork 0xde1e4 _CFStreamErrorFromCFError + 5000
6 CoreFoundation 0xc310 _CFRelease + 292
7 CFNetwork 0xc016c CFURLConnectionInvalidateConnectionCache + 7276
8 libobjc.A.dylib 0x5354 object_cxxDestructFromClass(objc_object*, objc_class*) + 116
9 libobjc.A.dylib 0x5090 objc_destructInstance + 80
10 libobjc.A.dylib 0x503c _objc_rootDealloc + 80
11 CFNetwork 0x1eca6c CFHTTPCookieStorageUnscheduleFromRunLoop + 237876
12 CFNetwork 0x1ed9f0 CFHTTPCookieStorageUnscheduleFromRunLoop + 241848
13 CFNetwork 0x55878 CFURLCredentialStorageSetDefaultCredentialForProtectionSpace + 27892
14 libobjc.A.dylib 0x5354 object_cxxDestructFromClass(objc_object*, objc_class*) + 116
15 libobjc.A.dylib 0x5090 objc_destructInstance + 80
16 libobjc.A.dylib 0x503c _objc_rootDealloc + 80
17 CoreFoundation 0xbec0 RELEASE_OBJECTS_IN_THE_ARRAY + 116
18 CoreFoundation 0xbdfc -[__NSArrayM dealloc] + 148
19 CFNetwork 0x183c54 _CFStreamErrorFromCFError + 683512
20 libobjc.A.dylib 0x5354 object_cxxDestructFromClass(objc_object*, objc_class*) + 116
21 libobjc.A.dylib 0x5090 objc_destructInstance + 80
22 libobjc.A.dylib 0x503c _objc_rootDealloc + 80
23 libobjc.A.dylib 0x5354 object_cxxDestructFromClass(objc_object*, objc_class*) + 116
24 libobjc.A.dylib 0x5090 objc_destructInstance + 80
25 libobjc.A.dylib 0x503c objc_rootDealloc + 80
26 Grow 0xc64860 CompositeEventMonitor.request(
:didParseResponse:) + 4355475552
27 libswiftCore.dylib 0x3a6d88 _swift_release_dealloc + 56
28 libswiftCore.dylib 0x3a8424 bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::doDecrementSlow<(swift::PerformDeinit)1>(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) + 136
29 Grow 0xc6e620 outlined init with copy of EventMonitor + 4355515936 (:4355515936)
30 libswiftCore.dylib 0x3a6d88 _swift_release_dealloc + 56
31 libswiftCore.dylib 0x3a8424 bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::doDecrementSlow<(swift::PerformDeinit)1>(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) + 136
32 libsystem_blocks.dylib 0x2438 _call_dispose_helpers_excp + 48
33 libsystem_blocks.dylib 0x23ec _Block_release + 252
34 libdispatch.dylib 0x4300 _dispatch_client_callout + 20
35 libdispatch.dylib 0x12998 _dispatch_main_queue_drain + 984
36 libdispatch.dylib 0x125b0 _dispatch_main_queue_callback_4CF + 44
37 CoreFoundation 0x3720c CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 16
38 CoreFoundation 0x33f18 __CFRunLoopRun + 1996
39 CoreFoundation 0x33668 CFRunLoopRunSpecific + 608
40 GraphicsServices 0x35ec GSEventRunModal + 164
41 UIKitCore 0x22c2b4 -[UIApplication _run] + 888
42 UIKitCore 0x22b8f0 UIApplicationMain + 340
43 UIKitCore 0x4559c8 __swift_destroy_boxed_opaque_existential_1Tm + 12220

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants