Use non-infinite timeout for async connection. (#2739)
authorJustin Anderson <jander-msft@users.noreply.github.com>
Wed, 17 Nov 2021 05:43:22 +0000 (21:43 -0800)
committerGitHub <noreply@github.com>
Wed, 17 Nov 2021 05:43:22 +0000 (21:43 -0800)
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcTransport.cs

index 10d13a100f3017fc4aff0c4fafc64951633117e4..44eeb6ca7e67cee1cf23274229f4ef4b83fc4403 100644 (file)
@@ -85,7 +85,13 @@ namespace Microsoft.Diagnostics.NETCore.Client
                     PipeDirection.InOut,
                     PipeOptions.Asynchronous,
                     TokenImpersonationLevel.Impersonation);
-                await namedPipe.ConnectAsync(token).ConfigureAwait(false);
+
+                // Pass non-infinite timeout in order to cause internal connection algorithm
+                // to check the CancellationToken periodically. Otherwise, if the named pipe
+                // is waited using WaitNamedPipe with an infinite timeout, then the
+                // CancellationToken cannot be observed.
+                await namedPipe.ConnectAsync(int.MaxValue, token).ConfigureAwait(false);
+                
                 return namedPipe;
             }
             else if (config.Transport == IpcEndpointConfig.TransportType.UnixDomainSocket)