fix: Ensure that the connection method is thread safe and always complete even exception#288
fix: Ensure that the connection method is thread safe and always complete even exception#288valentinperignon merged 4 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to make opening/closing the Transfers Realm database thread-safe and resilient to exceptions by serializing access and tracking the currently opened user DB.
Changes:
- Introduces a
Mutexto guardopenTransfersDb()/closeTransfersDb()access. - Tracks
currentTransfersUserIdto avoid reopening the same Transfers DB unnecessarily. - Wraps Realm open in
runCatchingand completes the deferred on success/failure.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
72dfdb5 to
c9885ee
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/RealmProvider.kt:105
- closeAllDatabases() now mutates currentTransfersUserId, but it (and closeTransfersDb) are not synchronized with transfersMutex. That undermines the thread-safety guarantees openTransfersDb is trying to establish and can race with concurrent openTransfersDb calls. Consider guarding closeTransfersDb/closeAllDatabases and any reads/writes of transfersAsync/currentTransfersUserId with the same transfersMutex.
suspend fun closeAllDatabases() {
currentTransfersUserId = null
closeAppSettingsDb()
closeUploadsDb()
closeTransfersDb()
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Abdourahamane Boinaidi <abdourahamane.boinaidi@infomaniak.com>
Signed-off-by: Abdourahamane Boinaidi <abdourahamane.boinaidi@infomaniak.com>
Signed-off-by: Abdourahamane Boinaidi <abdourahamane.boinaidi@infomaniak.com>
8ba8274 to
f362326
Compare
…ing in RealmProvider Agent-Logs-Url: https://github.com/Infomaniak/multiplatform-SwissTransfer/sessions/dc0e0e81-75d6-403c-a255-17f1843e803e Co-authored-by: sirambd <28200274+sirambd@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|



No description provided.