Xabaril / AspNetCore.Diagnostics.HealthChecks

Enterprise HealthChecks for ASP.NET Core Diagnostics Package
Apache License 2.0
4.1k stars 801 forks source link

TcpHealthCheck: not all resources are disposed? #1259

Open P47K0 opened 2 years ago

P47K0 commented 2 years ago

Hi,

I experience a memory leak in one of my micro services. I already tried a lot to discover the origin. I recently commented out the TcpHealthCheck and it looks like the memory usage of my service is stable now.

Are you sure that the following line cleans up everything? using (var tcpClient = new TcpClient(_options.AddressFamily))

In my code I also added a line to dispose the stream and I explicitly call close on the client. Here is a snippet of my code where I use and dispose a TcpClient:

                    using TcpClient client = await _listener.AcceptTcpClientAsync();
                    if (client.Connected)
                    {
                        using NetworkStream networkStream = client.GetStream();                        
                    }
                    client.Close();

Thanks in advance, Patrick

sungam3r commented 2 years ago

I don't use this healthcheck but what I can see from MS sources:

 public void Close()
    {
      if (Logging.On)
        Logging.Enter(Logging.Sockets, (object) this, nameof (Close), "");
      this.Dispose();
      if (!Logging.On)
        return;
      Logging.Exit(Logging.Sockets, (object) this, nameof (Close), "");
    }

In general I see nothing to fix in tcp health check for now though I posted #1273 to use specific overloads.