Skip to content

Instantly share code, notes, and snippets.

@MihaZupan
Created July 22, 2021 07:47
Show Gist options
  • Save MihaZupan/2e207c4c703272961b475e482e96afa3 to your computer and use it in GitHub Desktop.
Save MihaZupan/2e207c4c703272961b475e482e96afa3 to your computer and use it in GitHub Desktop.
using System;
using System.Diagnostics;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
// NoCheck is fine
// Offline/Online both consume a ton of memory
const X509RevocationMode RevocationCheckMode = X509RevocationMode.Offline;
Console.WriteLine(RevocationCheckMode);
PrintStatus(0);
for (int i = 1; i <= 20; i++)
{
try
{
const string Host = "revoked.badssl.com";
using var socket = new Socket(SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };
await socket.ConnectAsync(Host, 443);
using var networkStream = new NetworkStream(socket);
using var sslStream = new SslStream(networkStream);
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions
{
TargetHost = Host,
CertificateRevocationCheckMode = RevocationCheckMode
});
}
catch { }
PrintStatus(i);
}
using var proc = new Process
{
StartInfo = new ProcessStartInfo("dotnet-dump", $"collect --process-id {Environment.ProcessId}")
};
proc.Start();
await proc.WaitForExitAsync();
static void PrintStatus(int i)
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
long privateMB = Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024;
long managedKB = GC.GetTotalMemory(false) / 1024;
Console.WriteLine($"{i,2}: {privateMB} MB private, {managedKB} KB managed");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment