Repository navigation
Make server initialization log assertions thread-safe - #85899
Merged
Merged
Conversation
Use an ordered concurrent queue and a stable snapshot so late shutdown log callbacks cannot mutate a List during assertions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 2 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
mwiemer-microsoft
marked this pull request as ready for review
October 2, 2026 19:46
mwiemer-microsoft
enabled auto-merge (squash)
October 2, 2026 19:46
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused change safely resolves the demonstrated race without altering product behavior or test intent.
Review effort: Balanced
Findings: None
What changed in this PR
Makes Language Server log assertions thread-safe by snapshotting concurrently received messages before assertion enumeration.
Changes:
- Replaces
List<string>withConcurrentQueue<string>. - Runs existing assertions against one stable array snapshot.
| File | Description |
|---|---|
ServerInitializationTests.cs |
Prevents concurrent callback mutations from invalidating assertion enumeration. |
dibarbet
approved these changes
Oct 2, 2026
jasonmalinowski
approved these changes
Oct 2, 2026
This was referenced Oct 3, 2026
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.
AI-generated:
Summary
Extract the pre-existing test race discussed in #85776 into a separate fix against
main.TestUpdateLogLevelAppliesToNextWindowLogMessagesAsynccollectswindow/logMessagecallbacks in a mutableList<string>and reads it after disposing the server. The real shutdown callback can still insert a message after disposal returns, including during assertion enumeration.Use
ConcurrentQueue<string>and take oneToArray()snapshot for the four existing membership assertions. The queue retains enqueue order for debugging, unlike a concurrent bag. No product behavior, callback scheduling, xUnit imports, or completion-source options change.Controlled reproduction on main
Base:
d95fce4d81f2809e06449b1413752764ccc2bd45(xUnit v2).A temporary test used the actual
CreateLanguageServerAsyncserver and itsLogMessageReceivedevent, not a fabricated background producer:Shutting downnotification callback immediately before adding its message to the collection.server.DisposeAsync(). It completes while that callback is still blocked.With the original
List<string>, this fails with:With the queue and a snapshot obtained at the same point, the controlled interleaving passes. This proves a permitted failing interleaving on main; it does not establish the origin of the earlier Linux CI failure. The installed StreamJsonRpc 2.26.114 also documents that local methods may outlive disposal/
Completionand thatDispatchCompletionis the separate dispatch-draining primitive. The current client harness does not await that primitive. xUnit v2's collection membership assertions enumerate the collection.Temporary failing probe (add to ServerInitializationTests to reproduce on the base commit)
For the passing variant, use
ConcurrentQueue<string>/Enqueueand obtain the enumerator from theToArray()snapshot instead. The temporary probe was removed from the product diff; this description preserves it for reproduction.Validation
ServerInitializationTests: 3 passed.RunAnalyzersDuringBuild=trueand full LanguageServer unit-test run: 394 passed, 1 skipped, 0 failed.git diff --checkpassed.Microsoft Reviewers: Open in CodeFlow