Protect state dir against concurrent operations - #245
Open
bbannier wants to merge 1 commit into
Open
Conversation
This was
linked to
issues
Jul 24, 2026
bbannier
force-pushed
the
topic/bbannier/issue-139
branch
from
July 24, 2026 11:59
48bb19a to
8ebaa80
Compare
A big part of `zkg`'s work involves mutating its state dir, e.g., to update sources, refresh indices, or create temporary files. The code was built under the assumption that only a single `zkg` process would work on that state, so access was not controlled at all. This means that concurrent mutating operations against the state (of which we have many) could corrupt each other's expected state. Additionally, the functions we use to provide that functionality also do not cleanly cut along which part of the state they work on end to end making granular locking hard. What this patch does instead is to protect access to the manager's global state through a lock. With that all `zkg` invocations are effectively sequenced and races are impossible. This makes concurrent `zkg` invocations potentially much slower, but `zkg` was never designed for that use case anyway. We add a small test exercising concurrent, mutating access via `zkg list` which would have failed today without the lock, but it is not really clear that that operation would always perform state mutation. This closes #139 and maybe also #160 which could have had same underlying issue.
bbannier
force-pushed
the
topic/bbannier/issue-139
branch
from
July 24, 2026 12:03
8ebaa80 to
bfe1224
Compare
bbannier
marked this pull request as ready for review
July 24, 2026 13:54
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.
A big part of
zkg's work involves mutating its state dir, e.g., to update sources, refresh indices, or create temporary files. The code was built under the assumption that only a singlezkgprocess would work on that state, so access was not controlled at all. This means that concurrent mutating operations against the state (of which we have many) could corrupt each other's expected state. Additionally, the functions we use to provide that functionality also do not cleanly cut along which part of the state they work on end to end making granular locking hard.What this patch does instead is to protect access to the manager's global state through a lock. With that all
zkginvocations are effectively sequenced and races are impossible. This makes concurrentzkginvocations potentially much slower, butzkgwas never designed for that use case anyway.We add a small test exercising concurrent, mutating access via
zkg listwhich would have failed today without the lock, but it is not really clear that that operation would always perform state mutation.This closes both #139 and maybe also #160 which could have had same underlying issue.