RxSwift: Application crash sending `text` selector to RxTableViewDelegateProxy or RxCollectionViewDelegateProxy

Short description of the issue:

We’re seeing a crash among our userbase that is happening with alarming frequency however we have been unable to reproduce it or identify the root cause. A slack discussion was started here among 2 of us that are seeing this problem but we wanted to post here with the hopes that someone else may have an idea about something to look at.

This is the stack trace/crash:

-[RxCocoa.RxTableViewDelegateProxy text]: unrecognized selector sent to instance 0x28378a0d0

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x99288 __exceptionPreprocess
1  libobjc.A.dylib                0x16744 objc_exception_throw
2  CoreFoundation                 0x176fc4 +[NSObject(NSObject) _copyDescription]
3  CoreFoundation                 0x2de98 ___forwarding___
4  CoreFoundation                 0x2cf70 _CF_forwarding_prep_0
5  ContextKitExtraction           0x59ec +[CKContextContentProviderUIScene _bestVisibleStringForView:usingExecutor:]
6  ContextKitExtraction           0x4d7c +[CKContextContentProviderUIScene _donateContentsOfWindow:usingExecutor:withOptions:]
7  ContextKitExtraction           0x48fc __78+[CKContextContentProviderUIScene extractFromScene:usingExecutor:withOptions:]_block_invoke
8  ContextKitExtraction           0x54ac __64-[CKContextExecutor addWorkItemToQueue:withWorkItem:andContext:]_block_invoke
9  libdispatch.dylib              0x1e6c _dispatch_call_block_and_release
10 libdispatch.dylib              0x3a30 _dispatch_client_callout
11 libdispatch.dylib              0x11fa4 _dispatch_main_queue_drain
12 libdispatch.dylib              0x11b98 _dispatch_main_queue_callback_4CF
13 CoreFoundation                 0x51800 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
14 CoreFoundation                 0xb704 __CFRunLoopRun
15 CoreFoundation                 0x1ebc8 CFRunLoopRunSpecific
16 GraphicsServices               0x1374 GSEventRunModal
17 UIKitCore                      0x514648 -[UIApplication _run]
18 UIKitCore                      0x295d90 UIApplicationMain
19 <OurAppName>                   0x2b144c main + 20 (main.swift:20)
20 ???                            0x106badce4 (Missing)

I have scoured our code to see if we were somehow sending a text selector to anything in a weird way, this is not the case. Our app is large and uses tables in many screens but I haven’t found any misuse of rx.tems.

Here are the pertinent facts I’ve been able to collect about the problem:

  1. iOS 15.x.x only. We have users going back all the way to iOS 10.0 and no one experiences the crash other than iOS 15 users. We have a large user base so this shows up enough for us to have a large sample (thousands of crash events)
  2. SDK doesn’t matter. I have viewed crashes going back to before we upgraded to Xcode 13 (using Xcode 12). These users had the crash as well (running on iOS 15).
  3. The only API change of note in tables/collection views in iOS15 is the automatic prefetching which doesn’t involve code changes necessarily or invoke a text selector anywhere.
  4. The stack makes it clear that whatever the source is, it’s going through dynamic dispatch / objc_msgSend and being marshaled to the ui thread or called from the ui thread using dispatch.async as it unwinds the stack out to the runloop to invoke this invalid selector on the proxy.

This crash is alarming because it seems to only occur on iOS15. Users from previous versions of iOS do not exhibit this problem. We haven’t been able to determine if this is a bug in iOS, a bug in RxSwift or a bug in our usage of it. The os-specific nature of it makes me wonder if there’s an iOS bug or a bug in the RxSwift framework that just hasn’t come to light yet.

Any insights would be greatly appreciated.

Expected outcome:

No crashes

What actually happens:

Crash

Self contained code example that reproduces the issue:

I wish I had one or I’d be able to identify the problem 😦

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

RxSwift 6.2.0 - https://github.com/ReactiveX/RxSwift/commit/7c17a6ccca06b5c107cfa4284e634562ddaf5951

Platform/Environment

  • iOS
  • macOS
  • tvOS
  • watchOS
  • playgrounds

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

About 3% of our userbase is experiencing this. This includes users of other versions of iOS however that do not experience the issue at all.

Xcode version:

Xcode 13.2.1(13C100) although as stated it seems Xcode 12.4 was used at the time this first started showing up but before we noticed it.

Installation method:

  • CocoaPods
  • Carthage
  • Git submodules

I have multiple versions of Xcode installed: (so we can know if this is a potential cause of your issue)

  • yes (which ones)
  • no

Level of RxSwift knowledge: (this is so we can understand your level of knowledge and formulate the response in an appropriate manner)

  • just starting
  • I have a small code base
  • I have a significant code base

About this issue

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

Commits related to this issue

Most upvoted comments

We are experimenting with this patch. We don’t have conclusive results yet. I will update you when we do. But the root cause is still unknown.

@objc
extension RxCollectionViewDelegateProxy {
    var text: String {
        return String()
    }
}

@mkj-is we only have 3 days of it being live, but so far no crashes on the version with this patch in place in our app. I’ll update with any changes if more crashes happen with this patch in place.

We are experimenting with this patch. We don’t have conclusive results yet. I will update you when we do. But the root cause is still unknown.

@objc
extension RxCollectionViewDelegateProxy {
    var text: String {
        return String()
    }
}

Looking over the implementation of “DelegateProxy.swift” and “_RXDelegateProxy.m”, I’m not sure the logic is correct. In “DelegateProxy.swift”, “responds(to…” is checking super:

super.responds(to: aSelector)

But in “_RXDelegateProxy.m”, “forwardInvocation” is ignoring super.

The problem is that if the base class object also chooses to use object proxying, then the first check will return true (because the base class DOES respond to the selector) but the forwardInvocation call will fail with “selector not found”(since the message was never forward to “super”, which would have responded).

Hello @mkj-is , We’re having the exact same crash within our app, and today we were able to reproduce it. It seems like the crash is happening when the App is open and we try to use Siri

Hey all, Thanks for the reports.

To seriously look into this I need a non-Firebase crash report. Meaning an entire non-obfuscated crash report or xccrashpoint file that I can look into would be immensely helpful.

Looking at some of the traces here this doesn’t seem like something we could necessarily work around but more like a regression in iOS itself, but I’m happy to try and look into this if I get detailed enough crash details.

Thanks!

2022-06-07_23-03-54.9047_+0400-601c39d876053890e09ae677c7fd948089429656.crash.log

Small update: we found, that this stack trace appear much often on iOS 17.0.0 Afraid, that is may indicate some more serious issue with the app 😦

Screenshot 2023-08-23 at 10 12 05

In our project, we not only added text property but also sent the non-fatal to Firebase about it. Also, 100% on iOS 17.0.0 of them are coming with flag background=true in Firebase.

@liweican1992 That is because RACDelegateProxy is not part of RxSwift, but seems like it is a part of some old ReactiveCocoa version. Using correct class name should fix.

Since this bug is present in more FRP project I suspect this is indeed caused by some internal change in iOS.

@objc
extension RACDelegateProxy {
    var text: String {
        return String()
    }
}

Will we have a new release version of this workaround? Like 6.5.1?

Guys please check our solution for this crash #2546

As i see this MR is merged. May you say when new release will be?

Hey @SlashDevSlashGnoll @yan-zaitsev-hs - As I mentioned, I’d appreciate a quick PR with this “workaround”. For the time being it’s safe as far as I’m concerned.

It’s from Crashlytics there doesn’t seem to be a DL button so here’s a cleaned up copy/paste of the entire trace:

47.0 (936)
iOS 15.4.1
iPhone 13 Pro
May 31, 2022, 7:56:32 PM
Stack trace
Keys
Logs
Data


Fatal Exception: NSInvalidArgumentException
-[RxCocoa.RxTableViewDelegateProxy text]: unrecognized selector sent to instance 0x2835133a0
Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x99d78 __exceptionPreprocess
1  libobjc.A.dylib                0x16734 objc_exception_throw
2  CoreFoundation                 0x177b88 +[NSObject(NSObject) _copyDescription]
3  CoreFoundation                 0x2e988 ___forwarding___
4  CoreFoundation                 0x2da60 _CF_forwarding_prep_0
5  ContextKitExtraction           0x59ec +[CKContextContentProviderUIScene _bestVisibleStringForView:usingExecutor:]
6  ContextKitExtraction           0x4d7c +[CKContextContentProviderUIScene _donateContentsOfWindow:usingExecutor:withOptions:]
7  ContextKitExtraction           0x48fc __78+[CKContextContentProviderUIScene extractFromScene:usingExecutor:withOptions:]_block_invoke
8  ContextKitExtraction           0x54ac __64-[CKContextExecutor addWorkItemToQueue:withWorkItem:andContext:]_block_invoke
9  libdispatch.dylib              0x1e68 _dispatch_call_block_and_release
10 libdispatch.dylib              0x3a2c _dispatch_client_callout
11 libdispatch.dylib              0x11fa4 _dispatch_main_queue_drain
12 libdispatch.dylib              0x11b98 _dispatch_main_queue_callback_4CF
13 CoreFoundation                 0x522f0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
14 CoreFoundation                 0xc1f4 __CFRunLoopRun
15 CoreFoundation                 0x1f6b8 CFRunLoopRunSpecific
16 GraphicsServices               0x1374 GSEventRunModal
17 UIKitCore                      0x513e88 -[UIApplication _run]
18 UIKitCore                      0x2955ec UIApplicationMain
19 <MyAppName>                    0x2b144c main + 20 (main.swift:20)
20 ???                            0x101f1dce4 (Missing)

Crashed: com.google.firebase.crashlytics.ios.exception
SIGABRT ABORT 0x00000001c7e0db78
Crashed: com.google.firebase.crashlytics.ios.exception
0  <MyAppName>                    0x90d8b0 FIRCLSProcessRecordAllThreads + 393 (FIRCLSProcess.c:393)
1  <MyAppName>                    0x90dc90 FIRCLSProcessRecordAllThreads + 424 (FIRCLSProcess.c:424)
2  <MyAppName>                    0x904fd4 FIRCLSHandler + 34 (FIRCLSHandler.m:34)
3  <MyAppName>                    0x8ff740 __FIRCLSExceptionRecord_block_invoke + 215 (FIRCLSException.mm:215)
4  libdispatch.dylib              0x3a2c _dispatch_client_callout + 20
5  libdispatch.dylib              0x12c90 _dispatch_lane_barrier_sync_invoke_and_complete + 56
6  <MyAppName>                    0x8feee0 FIRCLSExceptionRecord + 219 (FIRCLSException.mm:219)
7  <MyAppName>                    0x8ff1e8 FIRCLSExceptionRecordNSException + 109 (FIRCLSException.mm:109)
8  <MyAppName>                    0x8feae0 FIRCLSTerminateHandler() + 273 (FIRCLSException.mm:273)
9  libc++abi.dylib                0x10f18 std::__terminate(void (*)()) + 20
10 libc++abi.dylib                0x10eb4 std::terminate() + 64
11 libobjc.A.dylib                0x2d268 objc::DenseMapBase<objc::DenseMap<objc_class*, PendingInitialize*, objc::DenseMapValueInfo<PendingInitialize*>, objc::DenseMapInfo<objc_class*>, objc::detail::DenseMapPair<objc_class*, PendingInitialize*> >, objc_class*, PendingInitialize*, objc::DenseMapValueInfo<PendingInitialize*>, objc::DenseMapInfo<objc_class*>, objc::detail::DenseMapPair<objc_class*, PendingInitialize*> >::FatalCorruptHashTables(objc::detail::DenseMapPair<objc_class*, PendingInitialize*> const*, unsigned int) const + 14
12 libdispatch.dylib              0x3a40 _dispatch_client_callout + 40
13 libdispatch.dylib              0x11fa4 _dispatch_main_queue_drain + 1020
14 libdispatch.dylib              0x11b98 _dispatch_main_queue_callback_4CF + 44
15 CoreFoundation                 0x522f0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
16 CoreFoundation                 0xc1f4 __CFRunLoopRun + 2532
17 CoreFoundation                 0x1f6b8 CFRunLoopRunSpecific + 600
18 GraphicsServices               0x1374 GSEventRunModal + 164
19 UIKitCore                      0x513e88 -[UIApplication _run] + 1100
20 UIKitCore                      0x2955ec UIApplicationMain + 364
21 <MyAppName>                    0x2b144c main + 20 (main.swift:20)
22 ???                            0x101f1dce4 (Missing)

com.apple.uikit.eventfetch-thread
com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0x14e0 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1b24 mach_msg + 76
2  CoreFoundation                 0x7820 __CFRunLoopServiceMachPort + 372
3  CoreFoundation                 0xbcac __CFRunLoopRun + 1180
4  CoreFoundation                 0x1f6b8 CFRunLoopRunSpecific + 600
5  Foundation                     0x18414 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 236
6  Foundation                     0x59cac -[NSRunLoop(NSRunLoop) runUntilDate:] + 92
7  UIKitCore                      0x48dfb0 -[UIEventFetcher threadMain] + 524
8  Foundation                     0x6855c __NSThread__start__ + 808
9  libsystem_pthread.dylib        0x19ac _pthread_start + 148
10 libsystem_pthread.dylib        0xe68 thread_start + 8

com.google.firebase.crashlytics.MachExceptionServer
com.google.firebase.crashlytics.MachExceptionServer
0  libsystem_kernel.dylib         0x14e0 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1b24 mach_msg + 76
2  <MyAppName>                    0x90782c FIRCLSMachExceptionServer + 192 (FIRCLSMachException.c:192)
3  libsystem_pthread.dylib        0x19ac _pthread_start + 148
4  libsystem_pthread.dylib        0xe68 thread_start + 8

Realm notification listener
Realm notification listener
0  libsystem_kernel.dylib         0x2e58 kevent + 8
1  <MyAppName>                    0xe75f30 realm::_impl::ExternalCommitHelper::listen() + 829816
2  <MyAppName>                    0xe76080 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >(void*) + 830152
3  libsystem_pthread.dylib        0x19ac _pthread_start + 148
4  libsystem_pthread.dylib        0xe68 thread_start + 8

com.sendbird.SocketRocket.NetworkThread
com.sendbird.SocketRocket.NetworkThread
0  libsystem_kernel.dylib         0x14e0 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1b24 mach_msg + 76
2  CoreFoundation                 0x7820 __CFRunLoopServiceMachPort + 372
3  CoreFoundation                 0xbcac __CFRunLoopRun + 1180
4  CoreFoundation                 0x1f6b8 CFRunLoopRunSpecific + 600
5  Foundation                     0x18414 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 236
6  SendBirdSDK                    0x668c4 -[SendBird_SRRunLoopThread main] + 70 (SendBird_SRRunLoopThread.m:70)
7  Foundation                     0x6855c __NSThread__start__ + 808
8  libsystem_pthread.dylib        0x19ac _pthread_start + 148
9  libsystem_pthread.dylib        0xe68 thread_start + 8

com.apple.NSURLConnectionLoader
com.apple.NSURLConnectionLoader
0  libsystem_kernel.dylib         0x14e0 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1b24 mach_msg + 76
2  CoreFoundation                 0x7820 __CFRunLoopServiceMachPort + 372
3  CoreFoundation                 0xbcac __CFRunLoopRun + 1180
4  CoreFoundation                 0x1f6b8 CFRunLoopRunSpecific + 600
5  CFNetwork                      0x2774d8 _CFURLStorageSessionDisableCache + 59988
6  Foundation                     0x6855c __NSThread__start__ + 808
7  libsystem_pthread.dylib        0x19ac _pthread_start + 148
8  libsystem_pthread.dylib        0xe68 thread_start + 8

com.apple.CFSocket.private
com.apple.CFSocket.private
0  libsystem_kernel.dylib         0x21a4 __select + 8
1  libsystem_kernel.dylib         0x21a4 select$DARWIN_EXTSN + 8
2  CoreFoundation                 0xab658 __CFSocketManager + 644
3  libsystem_pthread.dylib        0x19ac _pthread_start + 148
4  libsystem_pthread.dylib        0xe68 thread_start + 8

com.apple.root.utility-qos
com.apple.root.utility-qos
0  libsystem_kernel.dylib         0x2178 __ulock_wait + 8
1  libdispatch.dylib              0x441c _dlock_wait + 56
2  libdispatch.dylib              0x4118 _dispatch_wait_on_address + 140
3  libdispatch.dylib              0x47c0 _dispatch_group_wait_slow + 56
4  ContextKitExtraction           0x3f2c -[CKContextExecutor _awaitCompletion] + 52
5  libdispatch.dylib              0x1e68 _dispatch_call_block_and_release + 32
6  libdispatch.dylib              0x3a2c _dispatch_client_callout + 20
7  libdispatch.dylib              0x15280 _dispatch_root_queue_drain + 680
8  libdispatch.dylib              0x1596c _dispatch_worker_thread2 + 164
9  libsystem_pthread.dylib        0x1080 _pthread_wqthread + 228
10 libsystem_pthread.dylib        0xe5c start_wqthread + 8

com.apple.root.user-initiated-qos
com.apple.root.user-initiated-qos
0  libsystem_kernel.dylib         0x14e0 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1b24 mach_msg + 76
2  CoreFoundation                 0x7820 __CFRunLoopServiceMachPort + 372
3  CoreFoundation                 0xbcac __CFRunLoopRun + 1180
4  CoreFoundation                 0x1f6b8 CFRunLoopRunSpecific + 600
5  Foundation                     0x18414 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 236
6  Foundation                     0x18bd0 -[NSRunLoop(NSRunLoop) run] + 92
7  <MyAppName>                    0xf02e4 __35-[XYZEventManager initializeSocket]_block_invoke + 1294 (XYZEventManager.m:1294)
8  libdispatch.dylib              0x1e68 _dispatch_call_block_and_release + 32
9  libdispatch.dylib              0x3a2c _dispatch_client_callout + 20
10 libdispatch.dylib              0x15280 _dispatch_root_queue_drain + 680
11 libdispatch.dylib              0x1596c _dispatch_worker_thread2 + 164
12 libsystem_pthread.dylib        0x1080 _pthread_wqthread + 228
13 libsystem_pthread.dylib        0xe5c start_wqthread + 8

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

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

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

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

com.sendbird.sdk.core.runloop.thread
com.sendbird.sdk.core.runloop.thread
0  libsystem_kernel.dylib         0x14e0 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1b24 mach_msg + 76
2  CoreFoundation                 0x7820 __CFRunLoopServiceMachPort + 372
3  CoreFoundation                 0xbcac __CFRunLoopRun + 1180
4  CoreFoundation                 0x1f6b8 CFRunLoopRunSpecific + 600
5  Foundation                     0x18414 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 236
6  SendBirdSDK                    0x93c64 -[SBDRunLoopThread main] + 63 (SBDRunLoopThread.m:63)
7  Foundation                     0x6855c __NSThread__start__ + 808
8  libsystem_pthread.dylib        0x19ac _pthread_start + 148
9  libsystem_pthread.dylib        0xe68 thread_start + 8

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

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