Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Oct 17, 2025

Follow on after #14637. I now realize that there was a subtle race condition.

We use astId counter in the getter for program.comments, to check that the getter is not called after that AST is done with. Buffers are reused, so the buffer held in local reference is the same, but the contents of the buffer could have changed - it may now contain a different AST.

Previously, astId was incremented in deserializeProgram. So if comments getter is accessed after another AST is deserialized, it (rightly) throws.

But there's a small period of time in between walking the AST on JS side and the next call to deserializeProgram. During that period, the buffer may be being mutated on Rust side (in another thread), but astId hasn't been incremented yet, so the localAstId === astId check in comments getter will pass, and it won't throw an error as it should.

Fix this by incrementing astId as soon as traversal of this AST ends, instead of before deserializing the next AST begins.

Copy link
Member Author

overlookmotel commented Oct 17, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI A-ast Area - AST A-ast-tools Area - AST tools C-bug Category - Bug labels Oct 17, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 17, 2025

CodSpeed Performance Report

Merging #14727 will not alter performance

Comparing 10-17-fix_linter_plugins_prevent_comments_being_accessed_after_file_is_linted (5d6165e) with main (3029dfb)1

Summary

✅ 37 untouched

Footnotes

  1. No successful run was found on 10-17-refactor_linter_plugins_rename_function (4568276) during the generation of this report, so main (3029dfb) was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@overlookmotel overlookmotel marked this pull request as ready for review October 17, 2025 13:17
@overlookmotel overlookmotel self-assigned this Oct 17, 2025
@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Oct 17, 2025
@graphite-app graphite-app bot changed the base branch from 10-17-refactor_linter_plugins_rename_function to graphite-base/14727 October 17, 2025 13:18
Copy link
Member Author

overlookmotel commented Oct 17, 2025

Merge activity

@overlookmotel
Copy link
Member Author

cc @lilnasy FYI. I didn't spot this before. Highly unlikely this would be a problem in practice, but I think worth covering all bases...

@graphite-app graphite-app bot changed the base branch from graphite-base/14727 to main October 17, 2025 13:24
…linted (#14727)

Follow on after #14637. I now realize that there was a subtle race condition.

We use `astId` counter in the getter for `program.comments`, to check that the getter is not called after that AST is done with. Buffers are reused, so the buffer held in local reference is the same, but the *contents* of the buffer could have changed - it may now contain a *different* AST.

Previously, `astId` was incremented in `deserializeProgram`. So if `comments` getter is accessed after another AST is deserialized, it (rightly) throws.

But there's a small period of time in between walking the AST on JS side and the *next* call to `deserializeProgram`. During that period, the buffer may be being mutated on Rust side (in another thread), but `astId` hasn't been incremented yet, so the `localAstId === astId` check in `comments` getter will pass, and it won't throw an error as it should.

Fix this by incrementing `astId` as soon as traversal of *this* AST ends, instead of before deserializing the *next* AST begins.
@graphite-app graphite-app bot force-pushed the 10-17-fix_linter_plugins_prevent_comments_being_accessed_after_file_is_linted branch from 5d6165e to 47d8db1 Compare October 17, 2025 13:24
@graphite-app graphite-app bot merged commit 47d8db1 into main Oct 17, 2025
20 checks passed
@graphite-app graphite-app bot deleted the 10-17-fix_linter_plugins_prevent_comments_being_accessed_after_file_is_linted branch October 17, 2025 13:30
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Oct 17, 2025
graphite-app bot pushed a commit that referenced this pull request Oct 17, 2025
Follow-on after #14727.

Since we now have to call into deserializer module to update `astId` at end of linting a file, we may as well reset the buffers at that point too. This allows simplifying the `comments` getter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST A-ast-tools Area - AST tools A-cli Area - CLI A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants