Resolve DataStore IOException by checking single instance before Koin (#2044)#2090
Closed
zaibihsn wants to merge 5 commits into
Closed
Resolve DataStore IOException by checking single instance before Koin (#2044)#2090zaibihsn wants to merge 5 commits into
zaibihsn wants to merge 5 commits into
Conversation
v1.2.1: Hot fix for changing new backend
v1.3.0: New version
ed9ba38 to
c8a2fea
Compare
Owner
|
Create PR after you done, don't spam COMMITs |
Author
|
Completely understand, Max. I apologize for the extra commits; I had some trouble untangling my Git history locally after accidentally including the wrong files. I have submitted a new PR that contains only the single, clean commit pointed at the dev branch. You can review it here: #2091. Thank you for the guidance! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a user launches a second instance of the SimpMusic Desktop app while the first instance is still running in the background, the app crashes with a fatal java.io.IOException (Unable to rename ... settings.preferences_pb.tmp). This is caused by a file-locking collision on Windows because multiple instances of AndroidX DataStore are attempting to access the same preferences file.
Root Cause:
In DesktopApp.kt, startKoin { ... } was being executed before the application checked if it was a single instance (SingleInstanceManager.isSingleInstance). Because Koin initialized the dependency graph immediately, the newly spawned Java process created a duplicate DataStore object. This duplicate DataStore attempted to lock and modify settings.preferences_pb while the original process still held the lock.
Resolution:
Moved the SingleInstanceManager.isSingleInstance() check to the very beginning of the runDesktopApp function, entirely before startKoin is called.
Added a restoreRequest callback to ensure the window state is correctly brought back to the foreground when a duplicate launch is intercepted.
Now, if a second instance is launched, it immediately passes the request and deep links to the running instance and exits before it ever attempts to initialize Koin or touch the DataStore preferences file on disk.