fix: avoid race condition in async parallel parse/parseInline with hooks#3924
fix: avoid race condition in async parallel parse/parseInline with hooks#3924ordinary9843 wants to merge 3 commits intomarkedjs:masterfrom
Conversation
|
@ordinary9843 is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a race condition in the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a race condition that occurs during concurrent parsing with hooks by passing blockType as an argument to provideLexer and provideParser instead of mutating a shared hooks instance. The changes in src/Hooks.ts and src/Instance.ts are logical and correctly implement this fix.
However, I've identified a potential breaking change for custom hooks that rely on this.block, which seems to contradict the backward compatibility claim in the pull request description. I've left a detailed comment on this matter in src/Instance.ts. Addressing this point will ensure the change is either correctly documented as a breaking change or adjusted to maintain compatibility as intended.
17eeda1 to
fbe4eb4
Compare
|
You're right, thanks for pointing that out. Restored the assignment so existing custom hooks that read |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
UziTech
left a comment
There was a problem hiding this comment.
This looks like a good fix. Can you write some tests?
|
Added tests covering:
|
Closes #3836.
When
parse()andparseInline()are called concurrently with hooks present, both calls write toopt.hooks.block— the same shared hooks instance. The second call overwritesblockbefore the first call reachesprovideLexer()orprovideParser(), so both end up using the same lexer/parser (either both block or both inline).The fix passes
blockTypedirectly as an argument toprovideLexer(block)andprovideParser(block)so the shared hooks instance is never mutated during parsing. Theblockproperty is kept on_Hooksfor backwards compatibility with custom hook implementations that override these methods and readthis.block.All 1900 existing tests pass.