Skip to content

Conversation

Youssef1313
Copy link
Member

No description provided.

try
{
testAppPipeConnectionLoop = Task.Run(async () => await WaitConnectionAsync(cancellationToken), cancellationToken);
var testProcessExitCode = await StartProcess(processStartInfo);

Choose a reason for hiding this comment

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

should we pass cancellationToken to this? it seems that once we start the process we do not cancel here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. It's very possible that cancellation doesn't work very well today. @mariam-abdulla Do you know please?

Copy link
Member Author

@Youssef1313 Youssef1313 Sep 10, 2025

Choose a reason for hiding this comment

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

Let's follow-up in a separate issue either way. #50732

Copy link
Member

Choose a reason for hiding this comment

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

MTP handle the CTRL+C in a graceful way, here if I'm not mistaken we can only kill the process after the start and it's not graceful. So we can add a check on the boolean and don't start the process for "performance optimization" but we should avoid the kill.

Or add a client->server call(we're push only today) to signal the processes if we expect to "logically cancel" out of CTRL+C.

{
throw new InvalidOperationException(CliCommandStrings.MissingTestSessionEnd);
cancellationTokenSource.Cancel();
testAppPipeConnectionLoop?.Wait((int)TimeSpan.FromSeconds(30).TotalMilliseconds);

Choose a reason for hiding this comment

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

should we await it? the VS client uses the following vs-threading API https://github.com/microsoft/vs-threading/blob/849676611f654d73c84a9468b0ecc205294250e0/src/Microsoft.VisualStudio.Threading/ThreadingTools.cs#L105

also, when would we expect a timeout? if test process exits, then this method should hopefully completely pretty much immediately

Copy link
Member Author

Choose a reason for hiding this comment

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

Following-up in #50733

Copy link
Member Author

Choose a reason for hiding this comment

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

I go agree that it's expected for this task to complete almost immediately.

Copy link
Member

@MarcoRossignoli MarcoRossignoli Sep 10, 2025

Choose a reason for hiding this comment

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

I advice to keep always a timeout to avoid in case of bugs to hang forever and have a clear stack trace issue, when an api accept a time we should always set it.

@@ -276,7 +276,7 @@ private async Task<int> StartProcess(ProcessStartInfo processStartInfo)
{
Logger.LogTrace($"Test application arguments: {processStartInfo.Arguments}");

using var process = Process.Start(processStartInfo);
using var process = Process.Start(processStartInfo)!;

Choose a reason for hiding this comment

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

what is the maximum parallelism level for the dotnet CLI? have we tested with lots of test projects? we've seen Process.Start taking over the threadpool threads and this was causing contention in the VS client

Copy link
Member Author

Choose a reason for hiding this comment

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

We default to Environment.ProcessorCount unless specified by the user.

Copy link
Member Author

Choose a reason for hiding this comment

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

@drognanar What was the fix for the threadpool starvation issue on VS side? What would be the right way for dotnet test in this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

I used a combination of calling https://learn.microsoft.com/en-us/dotnet/api/system.threading.threadpool.setminthreads?view=net-9.0 to increase the threadpool size and specifically for the Process.Start it was put under an AsyncLock so that effectively one thread can enter this code path. this is because internally Process.Start runs under a lock on Windows and blocks a threadpool thread from running.

}
else
else if (_handshakeInfo.Value != currentHandshakeInfo)

Choose a reason for hiding this comment

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

under what circumstances do we expect multiple handshakes?

Copy link
Member Author

Choose a reason for hiding this comment

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

TestHostController+TestHost, or an orchestrator (e.g, Retry, or a future sharding orchestrator)

@Youssef1313 Youssef1313 merged commit cb2c757 into release/10.0.1xx Sep 10, 2025
29 checks passed
@Youssef1313 Youssef1313 deleted the dev/ygerges/protocol branch September 10, 2025 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants