Skip to content

Lock creation of CacheDir config - #4490

Merged
bdbaddog merged 1 commit into
SCons:masterfrom
mwichmann:maint/cachedir_lock
Mar 12, 2024
Merged

bdbaddog merged 1 commit into
SCons:masterfrom
mwichmann:maint/cachedir_lock

Conversation

@mwichmann

Copy link
Copy Markdown
Collaborator

When creating a new CacheDir, the config file is created in exclusive mode (that is, it fails if it exists), but there's a small timing window before the json dump to the file completes when another thread could read the config because it exists - but get a JSONDecodeError because it hasn't finished writing yet. Add locking, so the readers will have to wait until the writer is done.

Don't really know how to test this, it's a race that should have a pretty hard time occurring.

Fixes #4489

Contributor Checklist:

  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt (and read the README.rst)
  • I have updated the appropriate documentation

When creating a new CacheDir, the config file is created in
exclusive mode, but there's a timing window before the json dump
to the file completes when another thread could read the config
because it exists - but get a JSONDecodeError because it hasn't
finished writing yet.  Add locking so the readers will have to
wait until the writer is done.

Fixes SCons#4489

Signed-off-by: Mats Wichmann <[email protected]>
@bdbaddog
bdbaddog merged commit 8edf57f into SCons:master Mar 12, 2024
@mwichmann mwichmann added this to the 4.7 milestone Mar 13, 2024
@mwichmann
mwichmann deleted the maint/cachedir_lock branch March 13, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible race in CacheDir config

2 participants