Stop GC monitor thread on Ctrl+C
@@ -288,8 +288,6 @@ namespace Miningcore
// Pool stats
services.AddHostedService<StatsRecorder>();
}
-
- MonitorGc();
}
private static IHost host;
@@ -332,6 +330,8 @@ namespace Miningcore
return;
}
+ MonitorGc(ct);
+
if(clusterConfig.InstanceId.HasValue)
logger.Info($"This is cluster node {clusterConfig.InstanceId.Value}{(!string.IsNullOrEmpty(clusterConfig.ClusterName) ? $" [{clusterConfig.ClusterName}]" : string.Empty)}");
@@ -517,22 +517,30 @@ namespace Miningcore
throw new PoolStartupAbortException("Miningcore requires 64-Bit Windows");
}
- private static void MonitorGc()
+ private static void MonitorGc(CancellationToken ct)
{
var thread = new Thread(() =>
{
var sw = new Stopwatch();
- while(true)
+ while(!ct.IsCancellationRequested)
{
- var s = GC.WaitForFullGCApproach();
+ var s = GC.WaitForFullGCApproach(1000);
+
+ if(s == GCNotificationStatus.Timeout)
+ continue;
+
if(s == GCNotificationStatus.Succeeded)
{
logger.Info(() => "FullGC soon");
sw.Start();
- }
- s = GC.WaitForFullGCComplete();
+ while(!ct.IsCancellationRequested)
+ {
+ s = GC.WaitForFullGCComplete(1000);
+
+ if(s == GCNotificationStatus.Timeout)
+ continue;
if(s == GCNotificationStatus.Succeeded)
{
@@ -546,6 +554,8 @@ namespace Miningcore
sw.Reset();
}
}
+ }
+ }
});
GC.RegisterForFullGCNotification(1, 1);
