SecurePropertyStorage icon indicating copy to clipboard operation
SecurePropertyStorage copied to clipboard

Fix concurrency issues in Swift 6

Open alexruperez opened this issue 8 months ago • 0 comments

Description:

With the upcoming Swift 6 release, strict concurrency checks will be enforced. Our project, SecurePropertyStorage, currently has several warnings related to concurrency safety that need to be addressed to ensure compatibility and stability. This issue aims to track and resolve all these warnings.

Steps to Reproduce:

  1. Open SecurePropertyStorage.xcodeproj project file.
  2. Set the SWIFT_STRICT_CONCURRENCY flag to complete in the project build settings.
  3. Run SecurePropertyStorage-Package scheme tests.
  4. Observe the warnings related to concurrency safety.

Warnings to Fix:

Associated Value Warnings:

  1. InjectError enum warnings:

Static Property Warnings:

  1. Static property 'shared' is not concurrency-safe:
    • Locations:
      • Sources/Inject/InjectStorage.swift:7:24
      • Sources/Keychain/KeychainStorage.swift:9:24
      • Sources/Singleton/SingletonStorage.swift:10:24
      • Sources/UserDefault/UserDefaultsStorage.swift:10:24

Test Warnings:

  1. Static property 'allTests' is not concurrency-safe:

    • Locations:
      • Tests/SecurePropertyStorageTests/InjectTests.swift:195:16
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:252:16
      • Tests/SecurePropertyStorageTests/SingletonTests.swift:79:16
      • Tests/SecurePropertyStorageTests/UserDefaultTests.swift:243:16
  2. Let properties not concurrency-safe:

    • Locations:
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:10:5
      • Tests/SecurePropertyStorageTests/SingletonTests.swift:10:5
      • Tests/SecurePropertyStorageTests/UserDefaultTests.swift:10:5
  3. Call to main actor-isolated instance method waitForExpectations(timeout:handler:) in a synchronous nonisolated context:

    • Locations:
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:65:9
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:81:9
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:97:9
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:111:9
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:127:9
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:141:9
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:157:9
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:171:9
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:187:9
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:201:9
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:217:9
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:233:9
      • Tests/SecurePropertyStorageTests/KeychainTests.swift:249:9

Proposed Solution:

  • Ensure all associated values in Sendable-conforming enums are of Sendable types.
  • Modify static properties to conform to Sendable or isolate them to a global actor.
  • Ensure all tests and shared mutable states are concurrency-safe or properly isolated.

References:

alexruperez avatar May 30 '24 08:05 alexruperez