Skip to content

'try!' expression unexpectedly raised an error: disk I/O error (code: 10) when device is locked #3855

Closed
@mmathewsTableau

Description

@mmathewsTableau

Describe the bug

Whenever our app is locked and aws pinpoint is trying to read the database, we get this error followed by a crash. The error is expected because we have our app set to be NSFileProtectionComplete, which will encrypt the filesystem while the device is locked. However, our ask is that the Amplify library gracefully handles this scenario instead of crashing the app.

Steps To Reproduce

Steps to reproduce the behavior:
(this assumes you have an app that uses AWS pinpoint to record events remotely)

1. Set your app to have NSFileProtectionComplete for com.apple.developer.default-data-protection in your entitlements file.
2. Build your app and attach a debugger
3. Put a breakpoint here (https://github.com/aws-amplify/amplify-swift/blob/c13d7b723b236a68d32d04718011ad1f4c6f2f49/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/AnalyticsEventSQLStorage.swift#L145)
4. Use your app so to trigger the breakpoint
5. Once you hit the breakpoint, lock your device 
6. Wait 5 seconds... maybe more...
7. Step through the code

Expected behavior

The app should fails to read but app does not crash.

Amplify Framework Version

2.27.3

Amplify Categories

Analytics

Dependency manager

Swift PM

Swift version

5.9.2

CLI version

N/A

Xcode version

15.2

Relevant log output

<details>
<summary>Log Messages</summary>


Role:               Background
Exception Type:     EXC_BREAKPOINT 
Exception Subtype:  KERN_INVALID_ADDRESS


Fatal error: 'try!' expression unexpectedly raised an error: disk I/O error (code: 10)

0 libswiftCore.dylib +0xa7d10 _swift_unexpectedError
1 Tableau +0xdc0848           specialized FailableIterator.next() (<compiler-generated>)
2 Tableau +0xdb79f4           protocol witness for AnalyticsEventStorage.getEventsWith(limit:) in conformance AnalyticsEventSQLStorage (<compiler-generated>)
```

Is this a regression?

No

Regression additional context

No response

Platforms

iOS

OS Version

iOS 17.6.1

Device

iPhone 14.5

Specific to simulators

No

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions