Skip to content
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

chore(lsp): fix possible race condition with tests expecting 3 publishDiagnostics messages, but getting 2 or 1 #12868

Merged
merged 1 commit into from
Nov 24, 2021

Conversation

dsherret
Copy link
Member

The tests expect 3 publish notifications. It was possible for less than 3 to occur if two or more tasks set the diagnostics in the collection, exited the lock at the same time, then called publish_diagnostics.

…hDiagnostics messages

The tests expect 3 publish notifications. It was possible for less than 3 to occur if two or more tasks set the diagnostics in the collection, exited the lock at the same time, then called `publish_diagnostics`
let mut collection = collection.lock().await;
for diagnostic_record in diagnostics {
collection.set(DiagnosticSource::DenoLint, diagnostic_record);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Race condition was right here where the lock is released and then the lock was acquired in publish_diagnostics.

@dsherret dsherret marked this pull request as draft November 23, 2021 03:08
}
publish_diagnostics(client, collection, &snapshot).await;
publish_diagnostics(client, &mut collection, &snapshot).await;
Copy link
Member Author

Choose a reason for hiding this comment

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

@kitsonk would it be better to pass the diagnostics directly to this function? It seems like they get set in the collection and then they're taken from there. Maybe they shouldn't be put in the collection if lint isn't enabled or the specifier isn't enabled?

Copy link
Contributor

Choose a reason for hiding this comment

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

The considerations is that if you toggle a project as enabled or disabled (or for linting) the only way to clear diagnostics is to publish an empty set for each file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I'm not going to bother with this for now. I'll just fix this one issue in this PR.

@dsherret dsherret marked this pull request as ready for review November 23, 2021 15:23
Copy link
Contributor

@kitsonk kitsonk left a comment

Choose a reason for hiding this comment

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

LGTM

@kitsonk
Copy link
Contributor

kitsonk commented Nov 23, 2021

I have seen some situations recently with the 1.16 LSP where the diagnostics are "behind" the current version of the document and never catch up. I am wondering if this racy condition was part of it, so I will be trying that out and if not, will investigate further.

@dsherret
Copy link
Member Author

I have seen some situations recently with the 1.16 LSP where the diagnostics are "behind" the current version of the document and never catch up. I am wondering if this racy condition was part of it, so I will be trying that out and if not, will investigate further.

@kitsonk hmmm I'm not sure and don't think it would affect that. I was thinking some of the diagnostics code looks suspect, but I haven't looked at it in detail (only glanced at it). I think we could do something better here to improve it and eliminate that problem. Maybe I will look at it in more detail tomorrow.

@dsherret dsherret merged commit 0f90b46 into denoland:main Nov 24, 2021
@dsherret dsherret deleted the chore_tests_race_condition branch November 24, 2021 01:04
piscisaureus pushed a commit that referenced this pull request Nov 24, 2021
…hDiagnostics messages (#12868)

The tests expect 3 publish notifications. It was possible for less than 3 to occur if two or more tasks set the diagnostics in the collection, exited the lock at the same time, then called `publish_diagnostics`
piscisaureus pushed a commit to piscisaureus/deno that referenced this pull request Nov 24, 2021
…hDiagnostics messages (denoland#12868)

The tests expect 3 publish notifications. It was possible for less than 3 to occur if two or more tasks set the diagnostics in the collection, exited the lock at the same time, then called `publish_diagnostics`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants