Repository navigation
Conversation
…rage TokenStorage::read had no lock: a read racing an in-progress File.write could observe an empty file, YAML.safe_load returned nil, and the next add exploded with undefined method push for nil:NilClass. add and remove also read outside the lock, so two concurrent adds could overwrite each other's update (last writer wins, tokens silently lost). - read takes LOCK_SH; an empty file now parses as [] (no tokens), which fails closed for CSR validation - add/remove/remove_if run the read-modify-write cycle under a single LOCK_EX via a private modify helper (no nested lock, no self-deadlock) - parse is private and must only be called with the lock held
Contributor
|
I'd already opened a PR for this. #945 Was it no good? |
Author
|
My apologies, @alexjfisher - I should have checked existing PRs before opening this one. You fixed this months ago in #945, it's complete, CI-green, and honestly a better fix than mine (the atomic remove in validate_token also closes the read-then-remove window I left open). Closing mine in favor of yours. Thanks for pointing it out, and again, sorry for the noise. |
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.
Problem
TokenStorage::readhad no lock: a read racing an in-progressFile.writecould observe an empty file,YAML.safe_loadreturnednil, and the nextaddexploded withundefined method push for nil:NilClass.add/removealso read outside the lock, so two concurrent adds could overwrite each other's update (last writer wins, tokens silently lost).Fixes #39368
Fix
readtakesLOCK_SH; an empty file now parses as[](no tokens), which fails closed for CSR validation.add/remove/remove_ifrun the read-modify-write cycle under a singleLOCK_EXvia a privatemodifyhelper (no nested lock, no self-deadlock).parseis private and must only be called with the lock held.Verification
Token storage suite: 9 tests, 28 assertions, 0 failures (Ruby 3.3 container). Rubocop clean. Source-built smart-proxy image build + marker/syntax smoke checks pass in our docker/foreman pipeline.