Skip to content

Commit 4fcacb2

Browse files
committed
Merge branch 'rel/16.8' of https://github.com/microsoft/vstest into rel/16.8
2 parents 42b3463 + 088da43 commit 4fcacb2

File tree

1 file changed

+25
-38
lines changed

1 file changed

+25
-38
lines changed

src/Microsoft.TestPlatform.Extensions.BlameDataCollector/NetClientHangDumper.cs

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
namespace Microsoft.TestPlatform.Extensions.BlameDataCollector
55
{
66
using System;
7-
using System.Collections.Generic;
87
using System.Diagnostics;
98
using System.IO;
109
using System.Linq;
11-
using System.Threading;
12-
using System.Threading.Tasks;
1310
using Microsoft.Diagnostics.NETCore.Client;
1411
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
1512
using Microsoft.VisualStudio.TestPlatform.Utilities;
@@ -43,45 +40,35 @@ public void Dump(int processId, string outputDirectory, DumpTypeOption type)
4340

4441
var bottomUpTree = processTree.OrderByDescending(t => t.Level).Select(t => t.Process);
4542

46-
// Do not suspend processes with NetClient dumper it stops the diagnostic thread running in
47-
// them and hang dump request will get stuck forever, because the process is not co-operating.
48-
// Instead we start one task per dump asynchronously, and hope that the parent process will start dumping
49-
// before the child process is done dumping. This way if the parent is waiting for the children to exit,
50-
// we will be dumping it before it observes the child exiting and we get a more accurate results. If we did not
51-
// do this, then parent that is awaiting child might exit before we get to dumping it.
52-
var tasks = new List<Task>();
53-
var timeout = new CancellationTokenSource();
54-
timeout.CancelAfter(TimeSpan.FromMinutes(5));
5543
foreach (var p in bottomUpTree)
5644
{
57-
tasks.Add(Task.Run(
58-
() =>
59-
{
60-
try
61-
{
62-
var outputFile = Path.Combine(outputDirectory, $"{p.ProcessName}_{p.Id}_{DateTime.Now:yyyyMMddTHHmmss}_hangdump.dmp");
63-
EqtTrace.Verbose($"NetClientHangDumper.CollectDump: Selected dump type {type}. Dumping {process.Id} - {process.ProcessName} in {outputFile}. ");
64-
65-
var client = new DiagnosticsClient(p.Id);
66-
67-
// Connecting the dump generation logging to verbose output to avoid changing the interfaces again -> EqtTrace.IsVerboseEnabled
68-
// before we test this on some big repo.
69-
client.WriteDump(type == DumpTypeOption.Full ? DumpType.Full : DumpType.Normal, outputFile, logDumpGeneration: false);
70-
}
71-
catch (Exception ex)
72-
{
73-
EqtTrace.Error($"NetClientHangDumper.Dump: Error dumping process {p.Id} - {p.ProcessName}: {ex}.");
74-
}
75-
}, timeout.Token));
45+
try
46+
{
47+
p.Suspend();
48+
}
49+
catch (Exception ex)
50+
{
51+
EqtTrace.Error($"NetClientHangDumper.Dump: Error suspending process {p.Id} - {p.ProcessName}: {ex}.");
52+
}
7653
}
7754

78-
try
79-
{
80-
Task.WhenAll(tasks).GetAwaiter().GetResult();
81-
}
82-
catch (TaskCanceledException)
55+
foreach (var p in bottomUpTree)
8356
{
84-
EqtTrace.Error($"NetClientHangDumper.Dump: Hang dump timed out.");
57+
try
58+
{
59+
var outputFile = Path.Combine(outputDirectory, $"{p.ProcessName}_{p.Id}_{DateTime.Now:yyyyMMddTHHmmss}_hangdump.dmp");
60+
EqtTrace.Verbose($"NetClientHangDumper.CollectDump: Selected dump type {type}. Dumping {process.Id} - {process.ProcessName} in {outputFile}. ");
61+
62+
var client = new DiagnosticsClient(p.Id);
63+
64+
// Connecting the dump generation logging to verbose output to avoid changing the interfaces again -> EqtTrace.IsVerboseEnabled
65+
// before we test this on some big repo.
66+
client.WriteDump(type == DumpTypeOption.Full ? DumpType.Full : DumpType.Normal, outputFile, logDumpGeneration: false);
67+
}
68+
catch (Exception ex)
69+
{
70+
EqtTrace.Error($"NetClientHangDumper.Dump: Error dumping process {p.Id} - {p.ProcessName}: {ex}.");
71+
}
8572
}
8673

8774
foreach (var p in bottomUpTree)
@@ -96,6 +83,6 @@ public void Dump(int processId, string outputDirectory, DumpTypeOption type)
9683
EqtTrace.Error($"NetClientHangDumper.Dump: Error killing process {p.Id} - {p.ProcessName}: {ex}.");
9784
}
9885
}
99-
}
86+
}
10087
}
10188
}

0 commit comments

Comments
 (0)