confluentinc / confluent-kafka-dotnet

Confluent's Apache Kafka .NET client
https://github.com/confluentinc/confluent-kafka-dotnet/wiki
Apache License 2.0
2.78k stars 847 forks source link

CachedSchemaRegistryClient not Disposing X509Certificate2 #2187

Open bryantlikes opened 4 months ago

bryantlikes commented 4 months ago

Description

The CachedSchemaRegistryClient is creating certificates but not disposing them. This causes the temp files created at %APPDATA%\Roaming\Microsoft\Crypto\RSA to not be deleted.

Nuget version 2.3

How to reproduce

You'll need a pfx file. For this code the pfx file has no password.

using Confluent.SchemaRegistry;

var config = new SchemaRegistryConfig
{
    Url = "https://anything.com",
    SslKeystoreLocation = "[path to your pfx file]"
};

var x = new CachedSchemaRegistryClient(config);

x.Dispose();

Now check that file location and you'll see a guid file there. Each time you run it will add a new one. If you Dispose (or Reset) the certificate that file gets cleaned up.

Not sure of the best solution but one option would be in the RestClient to add the passed in certificates to a local variable. Then on Dispose for that client loop through the certificates and dispose them as well.

Checklist

Please provide the following information: