-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix Unix/macOS node reuse bugs + reduce idle timeout #13336
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #if NET | ||
|
|
||
| using Microsoft.Build.Internal; | ||
| using Microsoft.Build.Shared; | ||
| using Shouldly; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Build.UnitTests | ||
| { | ||
| /// <summary> | ||
| /// Tests for Unix node reuse bug fixes: | ||
| /// - SessionId = 0 on Unix (cross-terminal node reuse) | ||
| /// </summary> | ||
| public class UnixNodeReuseFixes_Tests | ||
| { | ||
| [Fact] | ||
| public void Handshake_OnUnix_SessionIdIsZero() | ||
| { | ||
| if (!NativeMethodsShared.IsUnixLike) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Two handshakes created from different contexts should have the same | ||
| // session ID (0) on Unix, enabling cross-terminal node reuse. | ||
| var h1 = new Handshake(HandshakeOptions.NodeReuse); | ||
| var h2 = new Handshake(HandshakeOptions.NodeReuse); | ||
|
|
||
| // Same handshake key means same session ID was used | ||
| h1.GetKey().ShouldBe(h2.GetKey()); | ||
| } | ||
|
Comment on lines
+19
to
+34
|
||
|
|
||
| [Fact] | ||
| public void Handshake_SessionIdComponent_IsZeroOnUnix() | ||
| { | ||
| if (!NativeMethodsShared.IsUnixLike) | ||
| { | ||
| return; | ||
| } | ||
|
Comment on lines
+39
to
+42
|
||
|
|
||
| var handshake = new Handshake(HandshakeOptions.NodeReuse); | ||
|
|
||
| // Key format: "options salt major minor build private sessionId" | ||
| // Last component should be 0 on Unix | ||
| string key = handshake.GetKey(); | ||
| string[] keyParts = key.Split(' '); | ||
| keyParts[keyParts.Length - 1].ShouldBe("0"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -289,8 +289,14 @@ protected Handshake(HandshakeOptions nodeType, bool includeSessionId, string too | |
| int sessionId = 0; | ||
| if (includeSessionId) | ||
| { | ||
| using var currentProcess = Process.GetCurrentProcess(); | ||
| sessionId = currentProcess.SessionId; | ||
| if (NativeMethodsShared.IsWindows) | ||
| { | ||
| using var currentProcess = Process.GetCurrentProcess(); | ||
| sessionId = currentProcess.SessionId; | ||
| } | ||
| // On Unix, getsid() returns the session leader PID which differs per terminal, | ||
| // preventing cross-terminal node reuse. Use 0 since Unix doesn't need | ||
| // RDP-style session isolation. | ||
| } | ||
|
Comment on lines
289
to
300
|
||
|
|
||
| _handshakeComponents = IsNetTaskHost | ||
|
|
@@ -409,7 +415,7 @@ internal static class CommunicationsUtilities | |
| /// <summary> | ||
| /// The timeout to connect to a node. | ||
| /// </summary> | ||
| private const int DefaultNodeConnectionTimeout = 900 * 1000; // 15 minutes; enough time that a dev will typically do another build in this time | ||
| private const int DefaultNodeConnectionTimeout = 30 * 1000; // 30 seconds | ||
|
Comment on lines
415
to
+418
|
||
|
|
||
| /// <summary> | ||
| /// Whether to trace communications | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,8 +44,10 @@ internal abstract class NodeEndpointOutOfProcBase : INodeEndpoint | |
| #if NETCOREAPP2_1_OR_GREATER | ||
| /// <summary> | ||
| /// The amount of time to wait for the client to connect to the host. | ||
| /// Reduced from 60s to 5s so that failed reuse probes don't block idle nodes | ||
| /// from reaching their connection timeout check. | ||
| /// </summary> | ||
| private const int ClientConnectTimeout = 60000; | ||
| private const int ClientConnectTimeout = 5000; | ||
|
Comment on lines
45
to
+50
|
||
| #endif // NETCOREAPP2_1 | ||
|
|
||
| /// <summary> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests use
if (!NativeMethodsShared.IsUnixLike) return;, which makes them silently pass on non-Unix platforms. Prefer[UnixOnlyFact](or another conditional test attribute) so the test is reported as skipped instead of passing without assertions.