Skip to content

fix: Ensure that the connection method is thread safe and always complete even exception#288

Merged
valentinperignon merged 4 commits intomainfrom
fix-logged-user
Apr 28, 2026
Merged

fix: Ensure that the connection method is thread safe and always complete even exception#288
valentinperignon merged 4 commits intomainfrom
fix-logged-user

Conversation

@sirambd
Copy link
Copy Markdown
Member

@sirambd sirambd commented Apr 28, 2026

No description provided.

Copilot AI review requested due to automatic review settings April 28, 2026 12:59
@sirambd sirambd changed the base branch from main to guest-api-v2 April 28, 2026 12:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Mutex to guard openTransfersDb() / closeTransfersDb() access.
  • Tracks currentTransfersUserId to avoid reopening the same Transfers DB unnecessarily.
  • Wraps Realm open in runCatching and completes the deferred on success/failure.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Base automatically changed from guest-api-v2 to main April 28, 2026 13:26
@sirambd sirambd requested a review from Copilot April 28, 2026 13:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

sirambd added 3 commits April 28, 2026 16:06
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>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 28, 2026

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:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx4g -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.14.4-bin/92wwslzcyst3phie3o264zltu/gradle-8.14.4/lib/gradle-daemon-main-8.14.4.jar (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@sonarqubecloud
Copy link
Copy Markdown

@valentinperignon valentinperignon merged commit c990554 into main Apr 28, 2026
6 checks passed
@valentinperignon valentinperignon deleted the fix-logged-user branch April 28, 2026 14:15
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.

5 participants