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

UI Hang Risk: Synchronous File Reading on Main Thread #504

Closed
ahmdmhasn opened this issue Sep 24, 2024 · 3 comments
Closed

UI Hang Risk: Synchronous File Reading on Main Thread #504

ahmdmhasn opened this issue Sep 24, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@ahmdmhasn
Copy link

ahmdmhasn commented Sep 24, 2024

Summary

Xcode's Thread Sanitizer warns about potential UI hangs due to synchronous file reading on the main thread in PersistentStorage.swift. This issue is highlighted by Xcode's known hang system, which suggests migrating away from String(contentsOf:, encoding:).

Expected Behavior

No warnings should be present, and file reading operations should not risk UI hangs.

Current Behavior

Xcode displays a warning for potential UI hangs and suggests an enhancement to the code.

Specific Location

File: PersistentStorage.swift

func getEventsString(eventBlock: EventBlock) -> String? {
    ...
    content = try String(contentsOf: eventBlock, encoding: .utf8) // <-- Warning shown here
    ...
}

Possible Solution

Use url.absoluteString instead

Steps to Reproduce

  1. Open the project in Xcode.
  2. Build the project using Amplitude SDK.
  3. Navigate to PersistentStorage.swift.
  4. Locate the getEventsString(eventBlock:) function.
  5. Observe the warning on the line using String(contentsOf:, encoding:).

Environment

  • Amplitude: 1.4.5
  • SDK Version: iOS 17.5
  • Device: iPhone 15
  • OS Version: macOS 14.5 (23F79)
  • Xcode: 15.4
@ahmdmhasn ahmdmhasn added the bug Something isn't working label Sep 24, 2024
@crleona
Copy link
Collaborator

crleona commented Sep 24, 2024

@ahmdmhasn which version of the Amplitude SDK are you using?

@ahmdmhasn
Copy link
Author

@crleona Amplitude 1.4.5

@crleona
Copy link
Collaborator

crleona commented Sep 25, 2024

@ahmdmhasn - you appear to be using an outdated version of https://github.com/amplitude/Amplitude-Swift, not https://github.com/amplitude/Amplitude-iOS. Please update.

@crleona crleona closed this as completed Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants