fix(lexer): ignore stale callbacks after reuse - #722
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new tokenization identity is not applied to the queued queueMicrotask path for string tokenization, which can still allow an earlier callback to run after a later tokenize call.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR makes N3Lexer reuse safer by preventing late data/end/error events from a previous stream tokenization from interfering with a subsequent tokenization on the same lexer instance.
Changes:
- Introduces a per-tokenization identity on the lexer instance and ignores stream events from older invocations.
- Adds a 3×3 regression matrix covering late stream events after syntax error, stream error, and normal completion.
File summaries
| File | Description |
|---|---|
src/N3Lexer.js |
Adds tokenization identity tracking and gates stream event handlers to ignore stale events after reuse. |
test/N3Lexer-test.js |
Adds regression tests ensuring late events from a prior stream do not affect the next tokenization callback or crash. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
|
🎉 This PR is included in version 2.7.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Reusing a
Lexercan leave old stream handlers or a queued string tokenizer referring to shared lexer state. If either runs after a latertokenizecall, it can deliver the new input's tokens to the previous callback or crash when the queued tokenizer encounters a null input.Give each tokenization an identity and ignore callbacks belonging to earlier invocations. The guard covers stream
data,end, anderrorevents as well as the microtask used for callback-based string tokenization. Eleven regression cases cover late stream events after failure or completion, and queued string tokenization superseded by either synchronous or callback-based string input.The stale-stream bug reproduces on
30c108e, before #721, so this fix is submitted independently of the lexer coordinate changes.Validation:
git diff --checkpass.