Skip to content

Ios fix file cache deadlock#9779

Merged
pinkisemils merged 2 commits intomainfrom
ios-fix-file-cache-deadlock
Feb 10, 2026
Merged

Ios fix file cache deadlock#9779
pinkisemils merged 2 commits intomainfrom
ios-fix-file-cache-deadlock

Conversation

@pinkisemils
Copy link
Collaborator

@pinkisemils pinkisemils commented Feb 6, 2026

We have deadlocks in the FileCache. Those are all the more pressing on iOS17, where the File Coordinator is broken (it notifies all presenters, even the one that is passed to the Coordinator upon initialization). These changes remove the lock, and instead guard the cache on a queue. I've also added some tests that fail to pass on main but do pass with the introduced changes.


This change is Reviewable

@pinkisemils pinkisemils added the iOS Issues related to iOS label Feb 6, 2026
@github-actions
Copy link

github-actions bot commented Feb 6, 2026

🚨 End to end tests failed. Please check the failed workflow run.

acb-mv
acb-mv previously approved these changes Feb 6, 2026
Copy link
Contributor

@acb-mv acb-mv left a comment

Choose a reason for hiding this comment

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

@acb-mv reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved.


ios/MullvadVPNTests/MullvadTypes/FileCacheTests.swift line 81 at r1 (raw file):

    // MARK: - Thundering herd

Good tests

@pinkisemils
Copy link
Collaborator Author

@acb-mv reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved.

ios/MullvadVPNTests/MullvadTypes/FileCacheTests.swift line 81 at r1 (raw file):

    // MARK: - Thundering herd

Good tests

Yes, tests that fail 😢 .

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.

@rablador reviewed 2 files and all commit messages, and made 3 comments.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @pinkisemils).


ios/MullvadVPNTests/MullvadTypes/FileCacheTests.swift line 227 at r1 (raw file):

        }

        // Both caches should be able to read a consistent value.

Isn't it more interesting to see if they contain the same value?


ios/MullvadTypes/FileCache.swift line 70 at r1 (raw file):

            let content = try JSONDecoder().decode(Content.self, from: Data(contentsOf: url))
            cacheQueue.sync { cachedContent = content }

Why do we write to memory here. It should already be handled in write below.


ios/MullvadTypes/FileCache.swift line 105 at r1 (raw file):

            cacheQueue.sync { cachedContent = content }
        } catch {

A log would be good here. Otherwise we can achieve the same thing with try? JSONDecoder[...] and get rid of the catch.

@pinkisemils pinkisemils force-pushed the ios-fix-file-cache-deadlock branch 2 times, most recently from 5e9797e to 483e487 Compare February 6, 2026 16:35
Copy link
Contributor

@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.

@mojganii made 3 comments.
Reviewable status: 0 of 2 files reviewed, 4 unresolved discussions (waiting on @acb-mv, @pinkisemils, and @rablador).


ios/MullvadTypes/FileCache.swift line 70 at r1 (raw file):

Previously, rablador (Jon Petersson) wrote…

Why do we write to memory here. It should already be handled in write below.

I guess it initiate the cachedContent if no cache is available.


ios/MullvadTypes/FileCache.swift line 105 at r1 (raw file):

Previously, rablador (Jon Petersson) wrote…

A log would be good here. Otherwise we can achieve the same thing with try? JSONDecoder[...] and get rid of the catch.

+1


ios/MullvadVPNTests/MullvadTypes/FileCacheTests.swift line 45 at r2 (raw file):

    }

    // MARK: - Cache behavior

typo: behaviour

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.

@rablador reviewed 2 files and all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @pinkisemils).

@pinkisemils pinkisemils force-pushed the ios-fix-file-cache-deadlock branch from 483e487 to 73f25c3 Compare February 9, 2026 19:36
Copy link
Collaborator Author

@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.

@pinkisemils made 3 comments and resolved 1 discussion.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @rablador).


ios/MullvadTypes/FileCache.swift line 70 at r1 (raw file):

Previously, mojganii wrote…

I guess it initiate the cachedContent if no cache is available.

If the cache is empty, we must read from the file itself.


ios/MullvadTypes/FileCache.swift line 105 at r1 (raw file):

Previously, mojganii wrote…

+1

We can't have a logger here since we don't want to depend on MullvadTypes :(
Fixed to not use a do block here.


ios/MullvadVPNTests/MullvadTypes/FileCacheTests.swift line 227 at r1 (raw file):

Previously, rablador (Jon Petersson) wrote…

Isn't it more interesting to see if they contain the same value?

Done.

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.

@rablador reviewed 2 files and all commit messages, and resolved 3 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved.

@pinkisemils pinkisemils force-pushed the ios-fix-file-cache-deadlock branch from 73f25c3 to a917164 Compare February 10, 2026 09:09
Copy link
Contributor

@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.

:lgtm:

@mojganii made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved.

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.

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

@pinkisemils pinkisemils merged commit f6a980e into main Feb 10, 2026
15 checks passed
@pinkisemils pinkisemils deleted the ios-fix-file-cache-deadlock branch February 10, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

iOS Issues related to iOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants