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

[Android]: Database locale issues #423

Merged
merged 3 commits into from
Sep 30, 2020
Merged

[Android]: Database locale issues #423

merged 3 commits into from
Sep 30, 2020

Conversation

krizzu
Copy link
Member

@krizzu krizzu commented Aug 21, 2020

Summary:

Trying to address: #422 #178

Those issues we've seen are related to locale changing and database connection not being closed properly. I could not reproduce it myself, so those are just preventive measures. Can't tell if this would help for sure.

The fix is to close db connection when activity is destroyed - it'll be reestablished on next startup (in case of locale change, activity is recreated).

Another one is to disable localized collators for db, which is the most suggested fix for Failed to change locale for db error.
I've moved this fix behind a flag that you need to set in gradle.properties in order to work.

This has been dropped due to possibility of unexpected behavior. More info about being consistent with locale collation in android docs.


If anyone is able to constantly reproduce the issue, please do let me know. You can try out this branch before it's released by pointing your package.json dependency to:

"@react-native-community/async-storage": "git+https://github.com/react-native-community/async-storage.git#fix/ensure-db-closed"

@kevinranks
Copy link

Would love to see this reviewed & merged soon if possible. We have many frustrated users that are receiving the issue in #422.

According to Android docs, one needs to be consistent when using
NO_COLLATION flag with how database was created, so changing this during
runtime makes no sense and can lead to some unexpected errors/behaviors
(SQLite default collation rule is BINARY).
@krizzu
Copy link
Member Author

krizzu commented Sep 28, 2020

Thanks @tido64 for having a look 🙏

According to Android docs, one needs to be consistent with what collation rules were used when creating the database. That means, setting this flag to NO_COLLATION during runtime could lead to some unexpected behaviors/errors. Besides, the main issue in this issue is database is locked error - which is also addressed by this PR.

@tido64
Copy link
Member

tido64 commented Sep 28, 2020

According to Android docs, one needs to be consistent with what collation rules were used when creating the database. That means, setting this flag to NO_COLLATION during runtime could lead to some unexpected behaviors/errors. Besides, the main issue in this issue is database is locked error - which is also addressed by this PR.

Does this mean that the problem is that we tried to open a database that was already opened in a different locale? Wouldn't restarting the app already close the database? Or is the implementation such that it is possible to leak connections?

@krizzu
Copy link
Member Author

krizzu commented Sep 28, 2020

Does this mean that the problem is that we tried to open a database that was already opened in a different locale?

I believe this is the case we see here.

Wouldn't restarting the app already close the database? Or is the implementation such that it is possible to leak connections?

This is exactly what I think is happening - changing locale restarts the activity, not the app process, so it leaks the db connection.

@tido64
Copy link
Member

tido64 commented Sep 28, 2020

This is exactly what I think is happening - changing locale restarts the activity, not the app process, so it leaks the db connection.

The repro steps in #178 mentions killing the app though. I thought that would close the connection?

@krizzu
Copy link
Member Author

krizzu commented Sep 28, 2020

The repro steps in #178 mentions killing the app though. I thought that would close the connection?

This is the most confusing part of the whole issue. I also thought the connection will be closed, but apparently it's not 🤷‍♂️ Dunno if we're not missing something here.

@krizzu
Copy link
Member Author

krizzu commented Sep 29, 2020

@tido64 I'll go ahead and merge this. Thanks for reviewing 🙏

@krizzu krizzu merged commit 9823e89 into master Sep 30, 2020
djhr pushed a commit to smartHelios/async-storage that referenced this pull request Oct 5, 2020
Make sure that we close db connection when 'host' is destroyed and re-create it when needed
@krizzu krizzu deleted the fix/ensure-db-closed branch January 18, 2021 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: Android This is Android specific
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants