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: Prevent crashes in multithreaded environments with sqlite. #495

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

crleona
Copy link
Collaborator

@crleona crleona commented Apr 23, 2024

Summary

We've seen some reported crashes in sqlite internals coming from our SDK. I suspect this is a threading issue as most of the crashes occur on background threads and the customer is using multiple instances of Amplitude.

Our current threading strategy is to dispatch all db operations to a single queue, and to recreate a connection per operation. This should work with the default multithread threading strategy, where sqlite is thread safe if connections aren't shared between threads.

But, dispatching to a single queue doesn't mean that we always run on the same thread, and we have no synchronization mechanism between instances of the SDK. This means that a single thread may run connections to two different databases, though none should simultaneously be open.

A possible fix is to opt us in to a more strict treading mode for sqlite - the FULL_MUTEX mode linearizes calls between threads and enables full multithreaded access to sqlite objects. There is a tradeoff in performance, though this should be minimal.

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: No

@crleona crleona requested a review from a team April 23, 2024 01:47
@crleona crleona merged commit 7020c95 into main Apr 24, 2024
2 checks passed
@crleona crleona deleted the AMP-98247-fix-sqlite-crashes branch April 24, 2024 00:15
github-actions bot pushed a commit that referenced this pull request Apr 24, 2024
## [8.19.2](v8.19.1...v8.19.2) (2024-04-24)

### Bug Fixes

* Prevent crashes in multithreaded environments with sqlite. ([#495](#495)) ([7020c95](7020c95))
* specify resource_bundle vs resource for resources in cocoapods ([#493](#493)) ([f780c12](f780c12))
Copy link

🎉 This PR is included in version 8.19.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants