redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

fix: guard against race conditions when resolving $refs

Open vlindhol opened this issue 5 months ago • 2 comments

What/Why/How?

We were using a global AJV instance shared for all documents, which might lead to race conditions.

Add a WeakMap holding an AJV instance for each document, and add some extra deduplication logic to prevent trying to look up the same reference multiple times within a document, just in case.

Reference

?

Testing

Race conditions are hard to trigger reliably, I think the best I can do right now is say "all existing tests must pass".

I have failures triggered by processing a large amount of .yaml files at once at work, but can't post those files publicly :/

Example of the type of errors I get:

Example validation errored: can't resolve reference #/components/schemas/Product from <filename>

as if local references can't be resolved! After applying this fix those errors go away.

Screenshots (optional)

Check yourself

  • [ ] Code changed? - Tested with redoc (internal)
  • [x] All new/updated code is covered with tests
  • [ ] New package installed? - Tested in different environments (browser/node)

Security

  • [ ] Security impact of change has been considered
  • [ ] Code follows company security practices and guidelines

vlindhol avatar Jun 12 '25 12:06 vlindhol

🦋 Changeset detected

Latest commit: fd87451c05866ef01231c58330571caeb6fc955b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@redocly/openapi-core Patch
@redocly/cli Patch
@redocly/respect-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Jun 12 '25 12:06 changeset-bot[bot]

Thanks for the contribution! We'll take a look at your PR in a bit.

tatomyr avatar Jun 17 '25 07:06 tatomyr

@tatomyr Great! Any updates on this? 😇

vlindhol avatar Jul 01 '25 11:07 vlindhol

@vlindhol sorry, haven't had a chance to look at it yet. We're currently busy with preparing the next version release. Will review it after we finish that.

tatomyr avatar Jul 04 '25 12:07 tatomyr

Closing this due to inactivity.

tatomyr avatar Oct 23 '25 11:10 tatomyr