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

Investigate crash in DiffableDataSource #7150

Merged
merged 1 commit into from
Nov 14, 2024
Merged

Conversation

mojganii
Copy link
Collaborator

@mojganii mojganii commented Nov 8, 2024

This PR fixes the carsh we have on UITableViewDiffableDataSource.


This change is Reviewable

@mojganii mojganii self-assigned this Nov 8, 2024
@mojganii mojganii added the bug label Nov 8, 2024
@mojganii mojganii force-pushed the fix-crash-on-location-view branch from a1267a3 to 70b7f8c Compare November 8, 2024 16:21
Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way we can unit test concurrent updates? Spawn two queues, both thrashing their own updates to the data source?

Reviewable status: 0 of 6 files reviewed, 1 unresolved discussion (waiting on @mojganii)


ios/MullvadVPN/Coordinators/CustomLists/AddLocationsDataSource.swift line 13 at r1 (raw file):

import MullvadTypes
import UIKit

How did this file ever work without having these imports?
Also, are we using Combine here? I can't identify anything Combine specific in the changes here, and I was under the impression we were not using Combine anywhere in our code.

rablador
rablador previously approved these changes Nov 11, 2024
Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The crash seems to be fixed! I have found two other things though:

  1. When first showing the location view, the selected location is not centered on screen.

  2. When selecting items between custom list and all locations, the snapshot state is sometimes lost. I believe this is related to not letting the LocationNode tree be the one source of truth. When toggling and updating selection the snapshot keeps a working state that doesn't reflect the node tree. It may be possible to make it work this way, but I doubt it will be completely reliable. What keeps track of expanded status is the showsChildren attribute on the node, but right now we don't update expanded status when toggling cells visible, which is a miss/bug from the original implementation. We should fix this and explicitly reapply the expanded status on the whole data set when data is reloaded (when creating snapshot items somewhere in setRelays). Ie. we only look at the node tree for data/structure and recreate the whole snapshot based on that.

Reviewed 6 of 6 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @pinkisemils)


ios/MullvadVPN/Coordinators/CustomLists/AddLocationsDataSource.swift line 13 at r1 (raw file):

Previously, pinkisemils (Emīls Piņķis) wrote…

How did this file ever work without having these imports?
Also, are we using Combine here? I can't identify anything Combine specific in the changes here, and I was under the impression we were not using Combine anywhere in our code.

They have been duplicated and a copy can be found a few lines below. This part should be removed.

Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @pinkisemils)

@buggmagnet buggmagnet added the iOS Issues related to iOS label Nov 11, 2024
buggmagnet
buggmagnet previously approved these changes Nov 11, 2024
Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 5 of 6 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @pinkisemils)

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 3 of 9 files reviewed, 1 unresolved discussion (waiting on @buggmagnet and @rablador)


ios/MullvadVPN/Coordinators/CustomLists/AddLocationsDataSource.swift line 13 at r1 (raw file):

Previously, rablador (Jon Petersson) wrote…

They have been duplicated and a copy can be found a few lines below. This part should be removed.

Yeah, this duplication should be removed.

@mojganii mojganii force-pushed the fix-crash-on-location-view branch from 4cf4ca5 to 66c756b Compare November 12, 2024 15:52
Copy link
Collaborator Author

@mojganii mojganii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rablador it seems my recent changes will solve the problem you've mentioned above. just we need to add some more uint test for that, which I'll do that in a bit. let me know if you found any new issue with that.
for checking and simulating concurrency issue you can get help from this snippet code :

    let concurrentQueue = DispatchQueue(label: "LocationDataSource.concurrentQueue", attributes: .concurrent)

        let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

        let numberOfConcurrentTasks = 1000

        let maxWordLength = 100

        for _ in 0 ..< numberOfConcurrentTasks {

            concurrentQueue.async {

                let randomText = String((0 ..< maxWordLength).compactMap { _ in

                    letters.randomElement()!

                })

                if (0..<maxWordLength).randomElement()! % 2 == 0 {

                    self.dataSource?.setRelays(relaysWithLocation, selectedRelays: self.selectedRelays)

                } else {

                    self.dataSource?.filterRelays(by: randomText)

                }

            }

        }

Reviewable status: 1 of 9 files reviewed, 1 unresolved discussion (waiting on @buggmagnet, @pinkisemils, and @rablador)


ios/MullvadVPN/Coordinators/CustomLists/AddLocationsDataSource.swift line 13 at r1 (raw file):

Previously, pinkisemils (Emīls Piņķis) wrote…

Yeah, this duplication should be removed.

that was my mistake. it's removed.

@mojganii mojganii changed the title Fix crash on UITableViewDiffableDataSource Investigate crash in DiffableDataSource Nov 13, 2024
@mojganii mojganii force-pushed the fix-crash-on-location-view branch from 66c756b to c40cf8d Compare November 13, 2024 16:01
Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 6 files at r3, 8 of 8 files at r4, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @mojganii and @pinkisemils)


ios/MullvadVPN/View controllers/SelectLocation/LocationDiffableDataSourceProtocol.swift line 42 at r4 (raw file):

    }

    func toggledItems(for cell: LocationCell, completion: (() -> Void)? = nil) {

Since this function no longer returns anything we should call it toggleItems instead.


ios/MullvadVPN/View controllers/SelectLocation/LocationViewControllerWrapper.swift line 114 at r4 (raw file):

        setUpSegmentedControl()
        addSubviews()
        entryLocationViewController.flatMap {

Although nifty we decided some time ago that we should not use flatMap in this way.

@mojganii mojganii force-pushed the fix-crash-on-location-view branch from c40cf8d to 6c03bd4 Compare November 14, 2024 09:24
Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 4 files at r5, all commit messages.
Dismissed @pinkisemils from a discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

rablador
rablador previously approved these changes Nov 14, 2024
Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Collaborator Author

@mojganii mojganii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved


ios/MullvadVPN/View controllers/SelectLocation/LocationDiffableDataSourceProtocol.swift line 42 at r4 (raw file):

Previously, rablador (Jon Petersson) wrote…

Since this function no longer returns anything we should call it toggleItems instead.

Done.


ios/MullvadVPN/View controllers/SelectLocation/LocationViewControllerWrapper.swift line 114 at r4 (raw file):

Previously, rablador (Jon Petersson) wrote…

Although nifty we decided some time ago that we should not use flatMap in this way.

Done.

Copy link
Collaborator Author

@mojganii mojganii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pinkisemils Unit testing for this will be addressed in a separate task. Here is the link: Testing Location DataSource for Stability

Reviewable status: 8 of 9 files reviewed, all discussions resolved (waiting on @rablador)

@mojganii mojganii requested a review from pinkisemils November 14, 2024 10:25
Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 5 of 8 files at r4, 3 of 4 files at r5, 1 of 1 files at r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@faern faern merged commit e3ce0eb into main Nov 14, 2024
11 checks passed
@faern faern deleted the fix-crash-on-location-view branch November 14, 2024 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug iOS Issues related to iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants