Skip to content

Commit da14225

Browse files
author
Mike McLaughlin
authored
Clean up IRuntime instance flushing (#3895)
* Fix ClrRuntime flushing which is causing random SOS test failures in gcroot * Code review feedback * More changes * Fix failures
1 parent 61c7f5b commit da14225

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/Microsoft.Diagnostics.DebugServices.Implementation/Runtime.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation
2020
public class Runtime : IRuntime, IDisposable
2121
{
2222
private readonly ClrInfo _clrInfo;
23-
private readonly IDisposable _onFlushEvent;
2423
private readonly ISymbolService _symbolService;
2524
private Version _runtimeVersion;
2625
private string _dacFilePath;
@@ -52,24 +51,19 @@ public Runtime(IServiceProvider services, int id, ClrInfo clrInfo)
5251
_serviceContainer.AddService<IRuntime>(this);
5352
_serviceContainer.AddService(clrInfo);
5453

55-
_onFlushEvent = Target.OnFlushEvent.Register(Flush);
56-
5754
Trace.TraceInformation($"Created runtime #{id} {clrInfo.Flavor} {clrInfo}");
5855
}
5956

6057
void IDisposable.Dispose()
61-
{
62-
_serviceContainer.RemoveService(typeof(IRuntime));
63-
_serviceContainer.DisposeServices();
64-
_onFlushEvent.Dispose();
65-
}
66-
67-
private void Flush()
6858
{
6959
if (_serviceContainer.TryGetCachedService(typeof(ClrRuntime), out object service))
7060
{
71-
((ClrRuntime)service).FlushCachedData();
61+
// The DataTarget created in the RuntimeProvider is disposed here. The ClrRuntime
62+
// instance is disposed below in DisposeServices().
63+
((ClrRuntime)service).DataTarget.Dispose();
7264
}
65+
_serviceContainer.RemoveService(typeof(IRuntime));
66+
_serviceContainer.DisposeServices();
7367
}
7468

7569
#region IRuntime

src/Microsoft.Diagnostics.DebugServices.Implementation/RuntimeProvider.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public RuntimeProvider(IServiceProvider services)
2828
/// <param name="startingRuntimeId">The starting runtime id for this provider</param>
2929
public IEnumerable<IRuntime> EnumerateRuntimes(int startingRuntimeId)
3030
{
31+
// The ClrInfo and DataTarget instances are disposed when Runtime instance is disposed. Runtime instances are
32+
// not flushed when the Target/RuntimeService is flushed; they are all disposed and the list cleared. They are
33+
// all re-created the next time the IRuntime or ClrRuntime instance is queried.
3134
DataTarget dataTarget = new(new CustomDataTarget(_services.GetService<IDataReader>()))
3235
{
3336
FileLocator = null

0 commit comments

Comments
 (0)