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

iOS 15/Xcode 13: Crash with RxTableViewDataSourceProxy #2368

Closed
5 of 18 tasks
Kn1kt opened this issue Sep 23, 2021 · 10 comments
Closed
5 of 18 tasks

iOS 15/Xcode 13: Crash with RxTableViewDataSourceProxy #2368

Kn1kt opened this issue Sep 23, 2021 · 10 comments

Comments

@Kn1kt
Copy link

Kn1kt commented Sep 23, 2021

Short description of the issue:

In iOS 15 setting some UITableViewDiffableDataSource as UITableView datasource leads to terminating app due to uncaught exception, when trying to acess to .rx.dataSource

Expected outcome:

It works as expected on iOS 13 and 14

What actually happens:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RxCocoa.RxTableViewDataSourceProxy _subclassOverridesMethodWithSelector:]: unrecognized selector sent to instance ...'

Self contained code example that reproduces the issue:

  let someTableView = UITableView(frame: .zero)
  let someDataSource = UITableViewDiffableDataSource<Int, Int>(tableView: someTableView) { tableView, indexPath, _ in
    return tableView.dequeueReusableCell(withIdentifier: "", for: indexPath)
  }
        
  let _ = someTableView.rx.dataSource
  

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

RxSwift 6.2.0

Platform/Environment

  • iOS
  • macOS
  • tvOS
  • watchOS
  • playgrounds

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

  • easy, 100% repro
  • sometimes, 10%-100%
  • hard, 2% - 10%
  • extremely hard, %0 - 2%

Xcode version:

  Xcode 13.0 (13A233)

Installation method:

  • CocoaPods
  • Carthage
  • Git submodules
  • Swift Package Manager

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
@hatched-cory
Copy link

We are also running into this issue on a production app, which is preventing us from using Xcode 13/iOS 15 SDKs.

We are currently working around it by manually removing any calls to UITableView Rx extensions that access the datasource e.g. .rx.itemMoved and .rx.itemDeleted.

What would be nice however is for these methods to fail gracefully on the iOS 15 SDK instead of crashing the app, since no warnings are raised at compile time.

I noticed that Apple's documentation for UITableViewDiffableDataSource explicitly calls out not changing a table view's data source once setting it, but it seems this wasn't actually an issue till now.

(oh also all of this applies to the equivalent UICollectionView structures as well)

@freak4pc
Copy link
Member

This is interesting since we're using iOS 15 with this in production and I'm not seeing any crashes around this.
Can you share a minimal reproducible project that I can easily pull and run?

Thanks!

@hatched-cory
Copy link

hatched-cory commented Sep 30, 2021

This is interesting since we're using iOS 15 with this in production and I'm not seeing any crashes around this. Can you share a minimal reproducible project that I can easily pull and run?

Thanks!

Hi @freak4pc! The code snippet @Kn1kt posted above is sufficient to trigger the crash, but I have made an example project as requested:

https://github.com/hatched-cory/RxSwiftDiffableCrash

Running on Xcode 13 in an iOS 15 sim (I'm using 13 Pro) is enough to repro

I believe the crash occurs when RxSwift/Cocoa tries to install its datasource proxy after the UITableViewDiffableDataSouce has been setup.

@Kn1kt
Copy link
Author

Kn1kt commented Sep 30, 2021

I noticed that Apple's documentation for UITableViewDiffableDataSource explicitly calls out not changing a table view's data source once setting it, but it seems this wasn't actually an issue till now.

Oh, actually this is the first time I've noticed this warning. This seems to be the main reason for this crash. I wonder if this can be fixed, because rx.methodInvoked() does not work without explicitly overriding the UITableViewDiffableDataSource methods.

@hatched-cory
Copy link

hatched-cory commented Sep 30, 2021

I noticed that Apple's documentation for UITableViewDiffableDataSource explicitly calls out not changing a table view's data source once setting it, but it seems this wasn't actually an issue till now.

Oh, actually this is the first time I've noticed this warning. This seems to be the main reason for this crash. I wonder if this can be fixed, because rx.methodInvoked() does not work without explicitly overriding the UITableViewDiffableDataSource methods.

After scanning the RxSwift code I kind of came to that conclusion as well. There might not be an elegant way for Rx to perform its necessary magicks when these datasources are in use. But I am not intimately familiar with the codebase, nor all the UIKit trickery. At the very least I'd love a more graceful fail state instead of a surprise runtime crash, though.

@sashkopotapov
Copy link

sashkopotapov commented Jan 5, 2022

@freak4pc Hey guys, any updates on this issue?

@freak4pc
Copy link
Member

freak4pc commented Jan 8, 2022

Thanks for the repro. Unfortunately I don't think there's anything we can do with this specific case (i.e. using UITableViewDiffableDataSource.

It seems to perform some sort of a hostile takeover on the delegate and data source - seems like everything is working fine if I simply use RxDataSources or vanilla UITableViewDelegate & UITableViewDataSource.

I won't have time to look into this soon, unfortunately, but am happy to accept a PR if someone wants to debug this further. I'm keeping this open so I can come back to it if I can find some free time.

Thanks!

@hatched-cory
Copy link

thanks @freak4pc appreciate your hard work on the library :) it is indeed tricky and for now we are just avoiding rx.* methods when using diffable data sources. but if I'm hit with inspiration I'll be here with a PR

@freak4pc
Copy link
Member

Closing this for now since this isn't something we can do much about.

@lgvv
Copy link

lgvv commented Dec 5, 2022

Has this issue been resolved?

Xcode 14
RxSwift 6.5.0

The same problem occurs.

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

No branches or pull requests

5 participants