fix: race condition when another process access simo file - #4
Merged
bruhtus merged 3 commits intoAug 31, 2026
Merged
Conversation
With the wrong timing, when another process try to access simo file at the same time when `simo` updating the file content (i.e pause/resume, change to focus/break session), those another process might read incomplete json file when trying to unmarshal the content. So write the new info in temporary file first, and then replace the old file with these temporary file to prevent another process from reading incomplete json file.
The problem is that using os.File Write() and Truncate() might not replace the current data with the new data, which means the data in simo file for test will be stale and that causing some of the test cases to fail when we run multiple test cases. Using os.WriteFile() solve that by using OpenFile() with O_TRUNC option underneath. Still not sure what is the difference here, but this is something to keep in mind.
Rather than hard coded the expected output, check the actual isNotify value is the same as the input value or not. This reduces the overhead of maintaining the expected output, and prevent print out misinformation when the actual isNotify value is not the same as input file. For example, "Got false, want false" if the isNotifyInput and isNotifyOutput is false but the actual isNotify value is true.
bruhtus
deleted the
fix/race-condition-when-another-process-access-simo-file
branch
August 31, 2026 05:17
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.
With the wrong timing, when another process try to access simo file at
the same time when
simoupdating the file content (i.e pause/resume,change to focus/break session), those another process might read
incomplete json file when trying to unmarshal the content.
So write the new info in temporary file first, and then replace the old
file with these temporary file to prevent another process from reading
incomplete json file.