Repository navigation
Conversation
`ValidatorFactory#validator_for` and `EnvelopeValidator#validator` memoized
into `Hash.new { |h, k| h[k] = ... }` caches without synchronization. On JRuby,
concurrent writes to such a hash can lose entries, so threads sharing a
factory or envelope validator could see a corrupted cache.
Guard both caches with a mutex, matching the approach used by the protobuf
record preparer.
Co-authored-by: Josh Wilson <joshuaw@squareup.com>
Signed-off-by: Josh Wilson <joshuaw@squareup.com>
jwils
requested review from
BrianSigafoos-SQ,
bsorbo,
ellisandrews-toast,
jwondrusch,
marcdaniels-toast,
myronmarston and
rossroberts-toast
as code owners
November 23, 2026 16:35
myronmarston
approved these changes
Nov 24, 2026
This branch has not been deployed
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.
Follow-up to #1442 (comment).
Two caches on the JSON ingestion path memoize into a
Hash.new { |h, k| h[k] = ... }default block without synchronization. On JRuby, concurrent writes to a hash like that can lose entries. The race test in the linked comment saw the wrong cache size in 193 of 200 runs on JRuby 10.0.2 and 0 of 200 on CRuby 4.0.0.Support::JSONSchema::ValidatorFactory#validator_for(@validators_by_type_name)JSONIngestion::EnvelopeValidator#validator(@validator_factories_by_version)Each cache is now a plain hash, initialized in the constructor and filled under a
Mutexwith||=. This matches how #1442's protoRecordPreparercaches its types. The envelope validator also used to create its cache hash lazily with||=, which was a second race; the hash is now created ininitialize. The factory-building logic moved into a privatebuild_validator_factorymethod, with no change in behavior.Testing:
script/run_gem_specs elasticgraph-supportandscript/run_gem_specs elasticgraph-json_ingestionpass with 100% line and branch coverage.script/type_checkandstandardrbon the changed files are clean.