Skip to content

Commit 962a9f9

Browse files
Copilottmat
andcommitted
Fix process cleanup timeout for no-hot-reload mode
Co-authored-by: tmat <41759+tmat@users.noreply.github.com>
1 parent 452af54 commit 962a9f9

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/BuiltInTools/dotnet-watch/CommandLine/EnvironmentOptions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ internal sealed record EnvironmentOptions(
6161
);
6262

6363
public TimeSpan GetProcessCleanupTimeout(bool isHotReloadEnabled)
64-
// If Hot Reload mode is disabled the process is restarted on every file change.
65-
// Waiting for graceful termination would slow down the turn around.
66-
=> ProcessCleanupTimeout ?? (isHotReloadEnabled ? TimeSpan.FromSeconds(5) : TimeSpan.FromSeconds(0));
64+
// Allow sufficient time for the process to exit gracefully and release resources (e.g., network ports).
65+
=> ProcessCleanupTimeout ?? TimeSpan.FromSeconds(5);
6766

6867
private int _uniqueLogId;
6968

test/dotnet-watch.Tests/CommandLine/EnvironmentOptionsTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,40 @@
33

44
namespace Microsoft.DotNet.Watch.UnitTests;
55

6+
public class EnvironmentOptionsTests
7+
{
8+
[Theory]
9+
[InlineData(true)]
10+
[InlineData(false)]
11+
public void GetProcessCleanupTimeout_WithoutEnvironmentVariable_ReturnsDefaultTimeout(bool isHotReloadEnabled)
12+
{
13+
var envOptions = new EnvironmentOptions(
14+
WorkingDirectory: "/test",
15+
MuxerPath: "dotnet",
16+
ProcessCleanupTimeout: null);
17+
18+
var timeout = envOptions.GetProcessCleanupTimeout(isHotReloadEnabled);
19+
20+
Assert.Equal(TimeSpan.FromSeconds(5), timeout);
21+
}
22+
23+
[Theory]
24+
[InlineData(true)]
25+
[InlineData(false)]
26+
public void GetProcessCleanupTimeout_WithEnvironmentVariable_ReturnsSpecifiedTimeout(bool isHotReloadEnabled)
27+
{
28+
var customTimeout = TimeSpan.FromSeconds(10);
29+
var envOptions = new EnvironmentOptions(
30+
WorkingDirectory: "/test",
31+
MuxerPath: "dotnet",
32+
ProcessCleanupTimeout: customTimeout);
33+
34+
var timeout = envOptions.GetProcessCleanupTimeout(isHotReloadEnabled);
35+
36+
Assert.Equal(customTimeout, timeout);
37+
}
38+
}
39+
640
public class BuildReporterTests
741
{
842
[Fact]

0 commit comments

Comments
 (0)