Skip to content

Connection objects on a Pool are not being released/pruned after Idle timeout. #3284

@loe-lobo

Description

@loe-lobo

Steps to reproduce

Update pg_hba.conf to trust the connection.
host all all all trust

    public class Program
    {
        public static void Main(string[] args)
        {
            for (var i = 0; i < 1000; i++)
            {
                Npgsql.NpgsqlConnection.ClearAllPools();

                var conStr = $"User ID=docker;Password={i};Host=postgres;Port=5432;Database=postgres;Connection Idle Lifetime=10;Connection Pruning Interval=5";
                using var connection = new NpgsqlConnection(conStr);

                connection.Open();

                using var cmd = new NpgsqlCommand("select 1", connection);
                cmd.Prepare();

                using var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    // do nothing
                }
                connection.Close();
                Thread.Sleep(5);
            }
        }
    }

The issue

All objects related to every opened connection are being kept in memory, even after executing GC and waiting a couple of minutes.

As you can verify below, the objects are kept in memory, most of them are moved to GC GEN 2.
image

The image below shows the allocation of the GC.
image

Further technical details

Npgsql version: 4.1.5
PostgreSQL version: 13
Operating system: Container Linux .net core 3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions