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

Fix background URLSession identifier collisions #351

Merged
merged 10 commits into from
Apr 18, 2024

Conversation

phil1995
Copy link
Collaborator

@phil1995 phil1995 commented Apr 6, 2024

This PR fixes #345.
It currently relies on the cloud-access-swift branch and can be used right now to test the PR: cryptomator/cloud-access-swift#33

Those changes are needed since issues appeared in the FileProviderExtension where we tried to use the same credential, which we usually used to make the identifier unique, for multiple vaults. Therefore, it was possible that more than one background URLSession gets created with the same identifier which then results in a failing URLSession.

Previously we could workaround this issue by just cache each CloudProvider but it seems like iOS creates now a own process for each domain.

Summary by CodeRabbit

  • New Features

    • Improved background session handling in CloudProviderDBManager for enhanced performance.
    • Enhanced vault provider creation in VaultDBManager for better session management.
  • Improvements

    • Updated methods for creating cloud providers to optimize performance.
    • Streamlined background session provider retrieval for improved efficiency.
  • Bug Fixes

    • Addressed potential collisions in background URLSession identifiers to prevent issues.

Copy link

coderabbitai bot commented Apr 6, 2024

Walkthrough

The update focuses on enhancing Cryptomator's cloud storage interaction, specifically improving background session support for various cloud providers. Changes include updating dependencies, refining provider management, and addressing specific issues like the "Content Unavailable" error when accessing multiple vaults on OneDrive. These modifications aim to streamline cloud service setups and improve session handling for a smoother user experience.

Changes

File Path Change Summary
Cryptomator.xcodeproj/.../Package.resolved, CryptomatorCommon/Package.swift Updated cloud-access-swift dependency to version 1.10.1.
Cryptomator/AppDelegate.swift, FileProviderExtensionUI/RootViewController.swift Adjusted cloud service setups, including OneDrive and PCloud configurations.
CryptomatorCommon/Sources/.../Manager/CloudProviderDBManager.swift Added CachedProvider struct for background sessions, updated provider methods.
CryptomatorCommon/Sources/.../Manager/VaultDBManager.swift Modified createVaultProvider to use vaultUID for background session IDs.
CryptomatorCommon/Sources/.../Manager/CloudProviderManagerTests.swift Updated assertions related to CloudProviderDBManager.cachedProvider.

Assessment against linked issues

Objective Addressed Explanation
Enable successful unlocking and display of multiple vaults on OneDrive (Issue #345)
Resolve "Content Unavailable" error for multiple vaults (Issue #345)
Improve handling of background tasks and sessions (Issue #345)

Possibly related issues

Poem

Among clouds and code, a rabbit's tale unfolds,
With each change made, a new story molds.
Vaults unlock seamlessly, errors take flight,
In skies of data, where sessions alight.
🌥️🐰💾
Through branches merged and tests unfurled,
Cryptomator's journey, a code world unfurled.


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ca61b4f and 3910d16.
Files selected for processing (1)
  • CryptomatorCommon/Sources/CryptomatorCommonCore/Manager/CloudProviderDBManager.swift (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • CryptomatorCommon/Sources/CryptomatorCommonCore/Manager/CloudProviderDBManager.swift

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f53e591 and bf9ae79.
Files selected for processing (6)
  • Cryptomator.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved (1 hunks)
  • Cryptomator/AppDelegate.swift (1 hunks)
  • CryptomatorCommon/Package.swift (1 hunks)
  • CryptomatorCommon/Sources/CryptomatorCommonCore/Manager/CloudProviderDBManager.swift (2 hunks)
  • CryptomatorCommon/Sources/CryptomatorCommonCore/Manager/VaultDBManager.swift (1 hunks)
  • FileProviderExtensionUI/RootViewController.swift (1 hunks)
Additional comments not posted (8)
CryptomatorCommon/Package.swift (1)

29-29: Ensure the branch feature/unique-identifier-bg-session of cloud-access-swift contains all necessary changes and is stable for production use. It's crucial to verify that this branch is up-to-date with any critical updates from the main or release branches to avoid missing important fixes or features.

Cryptomator/AppDelegate.swift (1)

Line range hint 1-1: Ensure that the removal of CloudProviderDBManager.shared.useBackgroundSession assignment in AppDelegate aligns with the new approach for managing background sessions at a more granular level. Verify that all necessary adjustments have been made elsewhere in the code to support this change effectively.

Cryptomator.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved (1)

62-63: The update to the cloud-access-swift package to use the branch feature/unique-identifier-bg-session is noted. Ensure that this branch is stable and contains all necessary features and fixes for the application. It's also important to plan for the transition back to a versioned release once the required features are merged into a stable release of cloud-access-swift.

CryptomatorCommon/Sources/CryptomatorCommonCore/Manager/CloudProviderDBManager.swift (3)

22-27: The introduction of the CachedProvider struct is a good approach for managing cloud providers with background session support. This encapsulation allows for cleaner management of session-related information. Ensure that the usage of CachedProvider throughout the CloudProviderDBManager aligns with the intended design and that thread safety is considered if access from multiple threads is expected.


49-53: When retrieving a background session provider, it's crucial to handle the case where a provider with the specified sessionIdentifier does not exist. Consider adding error handling or logging to inform about the fallback to creating a new provider, ensuring that this behavior is intentional and understood.


109-163: The method createBackgroundSessionProvider effectively creates providers with background session support. However, ensure that the maxPageSizeForFileProvider limit is well-documented and justified, as it impacts the number of items fetched in a single call. Additionally, verify that all providers support the creation with background sessions and that the session identifiers are managed securely and efficiently.

FileProviderExtensionUI/RootViewController.swift (1)

Line range hint 1-1: Ensure that the removal of CloudProviderDBManager.shared.useBackgroundSession assignment in RootViewController aligns with the new approach for managing background sessions at a more granular level. Verify that all necessary adjustments have been made elsewhere in the code to support this change effectively.

CryptomatorCommon/Sources/CryptomatorCommonCore/Manager/VaultDBManager.swift (1)

486-487: Using the vaultUID as the background URLSession identifier is a good approach to prevent identifier collisions.

Ensure that the rest of the system correctly handles these unique session identifiers, particularly in terms of session reuse and management, to avoid potential performance issues.

@tobihagemann tobihagemann added this to the 2.5.2 milestone Apr 18, 2024
@tobihagemann tobihagemann merged commit 3f16570 into develop Apr 18, 2024
3 checks passed
@tobihagemann tobihagemann deleted the bugfix/bg-session-identifier-collision branch April 18, 2024 16:30
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

Successfully merging this pull request may close these issues.

Content Unavailable Error with (single) MS OneDrive Accounts and multiple Vaults
2 participants