Skip to content

Protect state dir against concurrent operations - #245

Open
bbannier wants to merge 1 commit into
masterfrom
topic/bbannier/issue-139
Open

Protect state dir against concurrent operations#245
bbannier wants to merge 1 commit into
masterfrom
topic/bbannier/issue-139

Conversation

@bbannier

@bbannier bbannier commented Jul 24, 2026

Copy link
Copy Markdown
Member

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 both #139 and maybe also #160 which could have had same underlying issue.

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
bbannier force-pushed the topic/bbannier/issue-139 branch from 8ebaa80 to bfe1224 Compare July 24, 2026 12:03
@bbannier
bbannier marked this pull request as ready for review July 24, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant