Repository navigation
wg_state: retry a state file's replace while another program briefly holds it - #266
Merged
Merged
Conversation
…h on a missing key The check "4 processes, 4 different aliases, 50 locked increments each: 200" did not tell a child that stopped from an increment that was lost. - Each --child-add writes why it stopped to a file of its own: the lock not held (with its error), settings.ini unreadable (now exit 5; it never counts from 0 again), no counter (exit 6), or the write's error words with the counter it had read. - On a failure the parent prints the final count, every child's exit code and those reasons. - The checks read a setting through Val(), "(none)" for a missing key, instead of dereferencing Get(): a failed write or read fails the check instead of crashing the test. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…holds it Under heavy file activity (a build, an antivirus or indexer scan of a file just written) another program can hold settings.ini or the new temporary file for a moment. The single MoveFileExW then failed with ERROR_ACCESS_DENIED and the save was refused, although the state lock was held and nothing else in WrongGPU touched the file. - MoveIntoPlace: the rename into place is retried on ERROR_ACCESS_DENIED, ERROR_SHARING_VIOLATION and ERROR_LOCK_VIOLATION, with short pauses, for up to kMoveRetryMs (2 s). Any other error, or the same one after that time, fails as before: the file unchanged, the temporary file deleted, the error reported. - Used by WriteAtomic, UpdateStateFile (SetSettings) and the guard's completion marker. - Test seam "move-busy": an attempt fails as if the file were held. Tests: the first 3 replaces refused, the 4th writes the file; refused past the bound, WriteAtomic fails with error 5 after about 2 s and SetSettings reports AccessDenied, the file unchanged, no temporary file left; the same with a real handle opened read-only sharing read (as a scanner does): held for 300 ms the write succeeds, held past the bound it fails visibly. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
UpdateStateFile checked the file's identity once and then replaced it. With the retried replace, the program that held the file could write it and let go during the retries; the next attempt then overwrote its change silently. MoveIntoPlace takes an optional `unchanged` check, asked before every attempt after the first; false stops without replacing. UpdateStateFile passes "absent before, or still the same file" and returns Changed (temporary file deleted, the other program's bytes kept). WriteAtomic and the guard marker pass none. Test: the first replace refused while the holder writes the file: Changed, the holder's bytes stay, no temporary file left. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
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.
What
The state files' atomic replace (
MoveFileExWof the new temporary file oversettings.iniand the other state files) is now retried for up to 2 s when it fails withERROR_ACCESS_DENIED,ERROR_SHARING_VIOLATIONorERROR_LOCK_VIOLATION. These are the errors you get while another program briefly holds the file. The retry runs while the state lock is held. Before each retry,UpdateStateFilechecks that the file is still the one it read. If the program that held the file wrote it meanwhile, the save is refused (SetResult::Changed) and that program's bytes stay. Any other error, or the same error after 2 s, fails exactly as before: the file is unchanged, the temporary file is deleted, and the error is reported (WriteResult, andSetResult::AccessDenied/WriteFailed).WriteAtomic,UpdateStateFile(SetSettings) and the guard's completion marker all use it (MoveIntoPlaceinwg_state.h).Why
Under heavy file activity, such as a build or an antivirus or indexer scan of a file that was just written, another program can hold
settings.inior the temporary file for a moment. The single rename then failed with error 5 and the save was refused, even though the state lock was held and nothing else in WrongGPU touched the file. In the test suite this showed up as an occasional failure of the concurrent-increment check inwgshared_state. Children exited with code 4 (write failed, error 5). No increment was lost.Tests
move-busy) and the 4th writes the file.WriteAtomicfail with error 5 after about 2 s.SetSettingsreportsAccessDenied. The file is unchanged and no temporary file is left.Changed, the holder's bytes stay, and no temporary file is left.settings.iniis opened read-only with read sharing, as a scanner does. Held for 300 ms, the write succeeds. Held past the bound, it fails visibly with its error and the file is unchanged.Val(), so a missing key fails the check instead of crashing the test.test_wg_state: 69 passed, 0 failed (/W4 /WX).