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

fix(developer): prevent simultaneous opening of the same project by two processes #13341

Merged
merged 3 commits into from
Feb 27, 2025

Conversation

mcdurdin
Copy link
Member

@mcdurdin mcdurdin commented Feb 24, 2025

There is a race condition where two processes may both attempt to open the same project file. This appears to happen, for example, if an author double-clicks on a single-click shortcut, launching Keyman Developer twice in quick succession.

This fix adds a .lock file which is deleted automatically on close of the project or on normal or abnormal process termination. If a second process encounters the .lock file, it will simply open the welcome view instead of attempting to open the project.

Fixes: #11584
Fixes: KEYMAN-DEVELOPER-1PR

User Testing

  • TEST_PROJECT_LOADING: In Keyman Developer, verify that opening and closing a variety of projects works correctly, and that creating projects works correctly, and that opening projects from Windows Explorer works correctly. Try opening a project multiple times from Windows Explorer (double-click on the .kpj file) -- it should only open once. No crashes should occur.

…wo processes

There is a race condition where two processes may both attempt to open
the same project file. This appears to happen, for example, if an author
double-clicks on a single-click shortcut, launching Keyman Developer
twice in quick succession.

This fix adds a .lock file which is deleted automatically on close of
the project or on normal or abnormal process termination. If a second
process encounters the .lock file, it will simply open the welcome view
instead of attempting to open the project.

Fixes: #11584
Fixes: KEYMAN-DEVELOPER-1PR
@keymanapp-test-bot
Copy link

keymanapp-test-bot bot commented Feb 24, 2025

User Test Results

Test specification and instructions

Test Artifacts

Copy link
Contributor

@darcywong00 darcywong00 left a comment

Choose a reason for hiding this comment

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

lgtm

Maybe we add .lock to the .gitignore file in the keyboards repo

@mcdurdin
Copy link
Member Author

Review: I want to use a private appdata folder with hash of project filename (lowercased) instead of the current design of a .lock file next to the .kpj file. This will be less confusing for keyboard authors because the .lock file comes and goes and is never readable anyway.

For the project lock files, instead of using a filename in the same path
as the project file, with a .lock extension, use a hash of the project
filename in the Keyman Developer appdata folder, to avoid confusion and
conflict in project folders.

Fixes: #11584
@mcdurdin mcdurdin requested a review from darcywong00 February 25, 2025 08:21
@dinakaranr
Copy link

Test Results

I tested this issue with the attached KeymanDeveloper"18.0.199-beta-test-133341" build(25/02/2025) on Windows 10 and 11. Here I am sharing my observation.

  • TEST_PROJECT_LOADING (Passed): notes
  1. Install Keyman attached the KeymanDeveloper"18.0.199-beta-test-133341" PR build on the 25/02/2025.
  2. Open the "gff_amheric" keyboard project loaded in the keyman developer.
  3. Open the project by clicking the project menu --> open project.
  4. Select a project("Hindi modular") from the path.
  5. Verified that the project window appeared.
  6. Click on the "Window" icon.
  7. Type "Keyman Developer" and then click the developer's icon.
  8. Verified that the last edited project window appear.
  9. Repeat 6, and 7 steps.
  10. Verified that the "Keyman developer" window appeared and showed recent project lists.
  11. Navigate to the project's folder.(e.g. C:\Users\UserName\Documents\Keyman Developer\Projects\cspinyin)
  12. Double-click on the *.kpj icon.
  13. Verified that the project window appeared.
  14. Repeat the 11, and 12 steps.
  15. Verified that the "Keyman developer" window appeared and showed recent project lists.
    It works well. Thank you.

@keymanapp-test-bot keymanapp-test-bot bot removed the user-test-required User tests have not been completed label Feb 25, 2025
LoadGlobalProjectUI(ptUnknown, TikeCommandLine.StartupProjectPath);
if LoadGlobalProjectUI(ptUnknown, TikeCommandLine.StartupProjectPath) = nil then
begin
raise EProjectLoader.Create('Project is already open in another process');
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the lock file get left behind if the user reboots/shuts down while Keyman Developer is open?

I get frustrated by Android Studio when it does this. They include the path of the lock file to remove, so the user can manually remove it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Two things:

  1. The lock file is automatically deleted on close. It would take a hard reset for it to remain
  2. Keyman Developer will attempt to recreate it even if it exists -- so it does no real damage to leave it there in any case (and it's out of the way of the user now so it's really very harmless).

@mcdurdin mcdurdin merged commit b92d561 into beta Feb 27, 2025
6 checks passed
@mcdurdin mcdurdin deleted the fix/developer/11584-prevent-opening-same-project-twice branch February 27, 2025 16:18
@keyman-server
Copy link
Collaborator

Changes in this pull request will be available for download in Keyman version 18.0.202-beta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

bug(developer): starting multiple instances of TIKE simultaneously causes EFOpenError
4 participants