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

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

Closed
mmathewsTableau opened this issue Sep 5, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@mmathewsTableau
Copy link

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

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Sep 5, 2024
@5d
Copy link
Member

5d commented Sep 5, 2024

Hi @mmathewsTableau ,

Thank you for reporting the issue. I followed your reproduction steps, but I didn't encounter any crash logs. Instead, I observed the following behavior:

  1. System error log: "Operation not permitted."
  2. The app did not crash in background.
  3. When the app was brought to the foreground, the stuck event messages were eventually delivered to AWS Pinpoint.

System Error log is like this:

AutoFlushTimer triggered, flushing events
tcp_input [C1.1.1.1:3] flags=[R] seq=1227364307, ack=0, win=0 state=LAST_ACK rcv_nxt=1227364307, snd_una=1705778778
os_unix.c:44021: (1) seekAndRead(/private/var/mobile/Containers/Data/Application/91096F2A-3C50-4F55-9CE1-9B8B1D949F63/tmp/com/amazonaws/AWSPinpointRecorder/9a5f31013e1049d4af58a875ac10b078) - Operation not permitted
tcp_input [C1.1.1.1:3] flags=[R.] seq=1227364307, ack=1705778842, win=2048 state=CLOSED rcv_nxt=1227364307, snd_una=1705778778
os_unix.c:44021: (1) seekAndRead(/private/var/mobile/Containers/Data/Application/91096F2A-3C50-4F55-9CE1-9B8B1D949F63/tmp/com/amazonaws/AWSPinpointRecorder/9a5f31013e1049d4af58a875ac10b078) - Operation not permitted

Btw, I am testing with Xcode 15.4. Is the crash log you mentioned in the ticket generated by Xcode, or by another service such as Firebase Crashlytics?

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Sep 5, 2024
@5d 5d added question General question pending-maintainer-response Issue is pending response from an Amplify team member and removed pending-maintainer-response Issue is pending response from an Amplify team member pending-triage Issue is pending triage labels Sep 5, 2024
@mmathewsTableau
Copy link
Author

@5d , thanks for trying it and it's interesting you got different results. The crash log I submitted was from another service (ie bugsnag).

Let me try to repro again to see if there's more subtleties around the repro steps that I need to include.

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Sep 5, 2024
@mmathewsTableau
Copy link
Author

I tried it again locally and I got the same error you reported but also got the Fatal error as well

(/private/var/mobile/Containers/Data/Application/830D729C-B7E9-46EF-83FF-56C37C750DAA/tmp/com/amazonaws/AWSPinpointRecorder/7115f30a19c0155b73b7b43497357d21) - Operation not permitted <few non-relevant redacted lines> SQLite/Statement.swift:211: Fatal error: 'try!' expression unexpectedly raised an error: disk I/O error (code: 10) 2024-09-05 17:21:11.914863-0700 Tableau[490:21011] SQLite/Statement.swift:211: Fatal error: 'try!' expression unexpectedly raised an error: disk I/O error (code: 10)

I did have to try a few times consecutively locking and unlocking device before I got things in this state. In the initial attempt, I got the same behavior as you (no fatal error logged and no crash, just the "Operation not permitted" log).

So my steps to repro in this specific instance:

  1. Use your app so to trigger the breakpoint
  2. Once you hit the breakpoint, lock your device
  3. Wait 5 seconds... maybe more...
  4. Step through the code
  5. Bring app to foreground
  6. Repeat 4-8
image image

@5d
Copy link
Member

5d commented Sep 6, 2024

Hi @mmathewsTableau ,

Thanks for the updated information.
However, after several more attempts, I still couldn’t reproduce the issue with my phone.
But I did find a workaround solution from stephencelis/SQLite.swift#1075. I’ve applied this fix on the branch 5d/fix-sqlite-crash. Could you give it a try when you have a moment?

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Sep 6, 2024
@mmathewsTableau
Copy link
Author

Thanks @5d! I'm very excited to try out your fix. What is your recommended way to update my local Amplify package dependency to point to one with your fix? (back when we used cocoapods, it was relatively easy to patch a pod dependency locally but I don't have any experience doing it as xcode package dependencies)

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Sep 6, 2024
@5d
Copy link
Member

5d commented Sep 9, 2024

HI @mmathewsTableau ,

To change the dependency to a specific branch in Xcode using Swift Package Manager (SPM), follow these steps (instructions from GPT):

1. Open Your Xcode Project

Make sure your project or workspace is open in Xcode.

2. Navigate to Package Dependencies

  • In Xcode, go to your project in the Project Navigator on the left.
  • Select your project in the file list, then choose the project file (not the targets).
  • In the General tab, find Package Dependencies.

3. Edit the Dependency

If the package is already added, you need to update it:

  1. Select the dependency from the Package Dependencies list and click the "Edit" button (or click the “+” button to add a new dependency).
  2. This will open the Add Package Dependency interface.

4. Specify the Repository and Branch

If you’re adding a new dependency:

  • In the Package URL field, paste the URL of the Git repository.
  • In the next step, choose Branch as the option.
  • Enter the name of the branch that you want to use (e.g., develop, feature/xyz).

If you are editing an existing dependency:

  • Under Version Rules, select Branch and type the name of the branch you want to switch to.

5. Update the Package

After you’ve specified the branch, click Next, and then Finish. Xcode will resolve the package and fetch the specified branch.

Example of a Package Dependency Setup for a Specific Branch

If you're manually editing the Package.swift file (not in Xcode GUI), you would write something like this:

.package(url: "https://github.com/your/repo.git", .branch("develop")),

6. Clean and Build

Once you’ve added or edited the package dependency, make sure to clean and build your project:

  • Go to Product > Clean Build Folder.
  • Then build the project to ensure everything is linked correctly.

This will update your project to use the specific branch of the Swift package.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Sep 9, 2024
@mmathewsTableau
Copy link
Author

@5d, Thanks for the detailed steps. Was able to get a build going with your changes.

I tried my repro steps 5 times and I was never able to get it into the fatal state so the changes you made definitely helped and from what I can tell, prevents the crash. Would appreciate it if it can be included in a future release. Thanks!

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Sep 9, 2024
@5d
Copy link
Member

5d commented Sep 9, 2024

@mmathewsTableau ,
Thank you for testing this out. I’ve created a pull request(#3857) for the patch. We’ll let you know once it’s included in a new release.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Sep 9, 2024
@5d 5d added bug Something isn't working and removed question General question labels Sep 10, 2024
@5d
Copy link
Member

5d commented Sep 16, 2024

Hi @mmathewsTableau ,

The patch PR has been merged and included in the version 2.39.1 release. I am closing this issue for now, but feel free to reopen it if the problem persists.

@5d 5d closed this as completed Sep 16, 2024
Copy link
Contributor

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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