MichaCo / DnsClient.NET

DnsClient.NET is a simple yet very powerful and high performant open source library for the .NET Framework to do DNS lookups
https://dnsclient.michaco.net
Apache License 2.0
762 stars 136 forks source link

Memory-leak in latest versions in combination with full .net framework #192

Closed meerarno closed 5 months ago

meerarno commented 1 year ago

The latest versions of DnsClient (versions 1.5.0 and above) have a memory leak when used with the full .net framework (version 4.8 for example)

For example: for (int i = 0; i < 1000; i++) { var client = new LookupClient(); var response = await client.QueryAsync("google.com", QueryType.A); }

I think you should not use these higher versions with the full framework, but Visual Studio offers them as an valid update.

MichaCo commented 1 year ago

This is a really strange bug it seems. I don't think the implementation is doing anything wrong or bad, I'm actually correctly disposing the client. For some reason, if you run it under net48, some socket related objects stay in memory, even though the socket is closed and the UdpClient deleted.

Anyways, I'm able to reproduce it, which means this is a bug. Changing the Udp implementation to not write to the socket directly seems to fix the issue. I'll push an update soon.

Thanks for letting me know