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

[Background Mapping] Avoid crash when accessing DTOs while DB is being recreated #2934

Merged
merged 3 commits into from
Dec 13, 2023

Conversation

nuno-vieira
Copy link
Member

@nuno-vieira nuno-vieira commented Dec 12, 2023

🔗 Issue Links

https://github.com/GetStream/ios-issues-tracking/issues/625

🎯 Goal

Avoid crash when accessing DTOs from BackgroundDatabaseObserver while DB is being recreated

📝 Summary

There can be cases in which, because of the async nature of BackgroundDatabaseObserver, we can access a DTO that is no longer part of the DB if this one is being recreated. This can be reproduced in some cases when logging in and out pretty fast multiple times.

🛠 Implementation

This PR adds a thread guarded property (isDeletingDatabase) to BackgroundDatabaseObserver which will block any access to DTOs while the DB is being recreated.

🧪 Manual Testing Notes

Log in and out pretty fast multiple times

Expected result:
No crashes

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change follows zero ⚠️ policy (required)
  • This change should be manually QAed
  • Changelog is updated with client-facing changes
  • New code is covered by unit tests
  • Comparison screenshots added for visual changes
  • Affected documentation updated (docusaurus, tutorial, CMS)

🎁 Meme

Copy link

github-actions bot commented Dec 12, 2023

1 Message
📖 There seems to be app changes but CHANGELOG wasn't modified.
Please include an entry if the PR includes user-facing changes.
You can find it at CHANGELOG.md.

Generated by 🚫 Danger

@polqf polqf changed the title Bugfix/bg mapping map deleted item [Background Mapping] Avoid crash when accessing DTOs while DB is being recreated Dec 13, 2023
@polqf polqf marked this pull request as ready for review December 13, 2023 09:26
@polqf polqf requested a review from a team as a code owner December 13, 2023 09:26
@polqf polqf force-pushed the bugfix/bg-mapping-map-deleted-item branch from 6e81f13 to 787102d Compare December 13, 2023 09:26
@testableapple testableapple deleted the bugfix/bg-mapping-map-deleted-item branch December 13, 2023 09:29
@testableapple testableapple restored the bugfix/bg-mapping-map-deleted-item branch December 13, 2023 09:30
@testableapple testableapple reopened this Dec 13, 2023
Copy link

sonarcloud bot commented Dec 13, 2023

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

47 New issues
0 Security Hotspots
90.8% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@nuno-vieira nuno-vieira merged commit 0ffb112 into develop Dec 13, 2023
17 of 27 checks passed
@nuno-vieira nuno-vieira deleted the bugfix/bg-mapping-map-deleted-item branch December 13, 2023 11:07
nuno-vieira added a commit that referenced this pull request Dec 13, 2023
…g recreated (#2934)

* Make sure the object is valid before mapping it

* Keep track of DB being deleted on BackgroundDatabaseObserver

* Improve API to track if database is being removed

---------

Co-authored-by: Pol Quintana <pol.quintana1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants