Skip to content

Resolve DataStore IOException by checking single instance before Koin (#2044)#2090

Closed
zaibihsn wants to merge 5 commits into
maxrave-dev:devfrom
zaibihsn:fix-datastore-windows-crash
Closed

Resolve DataStore IOException by checking single instance before Koin (#2044)#2090
zaibihsn wants to merge 5 commits into
maxrave-dev:devfrom
zaibihsn:fix-datastore-windows-crash

Conversation

@zaibihsn
Copy link
Copy Markdown

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.

@maxrave-dev maxrave-dev changed the base branch from main to dev May 31, 2026 12:44
@zaibihsn zaibihsn force-pushed the fix-datastore-windows-crash branch from ed9ba38 to c8a2fea Compare May 31, 2026 15:21
@maxrave-dev
Copy link
Copy Markdown
Owner

Create PR after you done, don't spam COMMITs

@zaibihsn
Copy link
Copy Markdown
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!

@zaibihsn zaibihsn deleted the fix-datastore-windows-crash branch May 31, 2026 18:25
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.

2 participants