Skip to content

Fix bug in ensureProjectStructuresUpToDate that [maybe?] can lead to poisoned cache #47464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

MarcCelani-at
Copy link

@MarcCelani-at MarcCelani-at commented Jan 16, 2022

This PR may improve (but does not seem to fully fix) #47274

The return value of updateProjectIfDirty is not obvious to callers. It returns true if the project is dirty but when the set of files in the project stayed the same (Project.updateGraph returns true if set of files in the project stays the same and false - otherwise). I have to imagine that this is a bug, because this is a very nuanced return value.

There is only one call site of updateProjectIfDirty that checks the return value - in ensureProjectStructuresUptoDate. That code appears to assume that the function returns true if the project changed.

This PR changes updateProjectIfDirty to return boolean in similar fashion to updateGraph (true if set of files in the project stays the same, false otherwise). Update the call site to properly handle the return value.

I don't have a good sense of how to test this. Happy to add a unit test if someone can point me to another test that tests something similar.

Suspect that...

Fixes #47274

@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jan 16, 2022
@MarcCelani-at MarcCelani-at changed the title Update editorServices.ts Fix bug in ensureProjectStructuresUpToDate that [maybe?] can lead to poisoned cache Jan 16, 2022
@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jan 16, 2022
Copy link
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Can we add a @returns JSDoc comment on that function that explains what the boolean means? It’s still a little hard to grok it without navigating all the way into Project#updateGraph.

@DanielRosenwasser
Copy link
Member

Looks like we won't get this in in time for the beta.

Regardless I think we need to get a test case that failed earlier.

@MarcCelani-at
Copy link
Author

I don't understand this code well enough to know what's going on here, this was honestly a shot in the dark. It doesn't fix the underlying issue for my repro (large checkout in a mono-repo). The existing code just looks suspicious given what the code is doing and the comments.

It would be great if someone more familiar with this code can look at it and maybe decide if it's a bug or not (I know this is a weird request haha)

Actually, a better request would be that...I'm very eager to pair-debug with someone from the typescript team. I have an extremely clear repro of the issue (#47274) in my mono-repo, which unfortunately I can't grant the typescript team access to, but I'd happy share screen over zoom and spend cycles on my side getting to the bottom of it. Sadly, this shot in the dark is the only thing I've spotted after probably a good 15+ hours debugging this issue.

@@ -1192,7 +1192,7 @@ namespace ts.server {
let hasChanges = this.pendingEnsureProjectForOpenFiles;
this.pendingProjectUpdates.clear();
const updateGraph = (project: Project) => {
hasChanges = updateProjectIfDirty(project) || hasChanges;
hasChanges = !updateProjectIfDirty(project) || hasChanges;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect change.. the intension here is to call updateGraph and get its return value only if it is marked as dirty.. So original code is correct in what it intends to do..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks for confirming. I'll abandon this PR. It anyway did not show any change in correctness. Though it's a little unfortunate that this change does not trigger any unit test failures.

@MarcCelani-at MarcCelani-at deleted the fixUpdateProjectIfDirty branch March 27, 2022 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
5 participants