redocly-cli
redocly-cli copied to clipboard
fix: guard against race conditions when resolving $refs
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
🦋 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
Thanks for the contribution! We'll take a look at your PR in a bit.
@tatomyr Great! Any updates on this? 😇
@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.
Closing this due to inactivity.