Skip to content

Add the possibility to configure a maximum connexion lifetime for idle pool #632

@ArthurKnoep

Description

@ArthurKnoep

Description

Currently it is possible to configure a maximum connexion lifetime for the database connexion pool (which correspond to the underlaying function sql.SetConnMaxLifetime: https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime), but there is no way (unless there is one ?) to configure the connexion maximum lifetime for the idle connexions (sql.SetConnMaxIdleTime: https://golang.org/pkg/database/sql/#DB.SetConnMaxIdleTime)

In my use case I need to set a maximum connexion lifetime for the idle connexions so that the connexion pool entirely disconnect from the database after a period of innactivity. The main goal is to allow our RDS serverless database to scale down when no request are made so that we can save on cost.

Steps to Reproduce the Problem

I create my connexion with the following code:

connDetails := &pop.ConnectionDetails{
    URL:             <URL to the database>,
    IdlePool:        8,
    ConnMaxLifetime: time.Duration(30 * time.Second),
    Pool:            16,
    Options:         <an optional map of option>,
}

c, err = pop.NewConnection(connDetails)
if err != nil {
    panic(err)
}

if err := c.Open(); err != nil {
    panic(err)
}

Please, keep in mind that those values are just example values for my demonstration

Expected Behavior

I expect to be able to update the connexion max idle time

Info

Not that it matters but I'm running a proud Ubuntu 20.10 with go1.16.2.
I'm using pop in version 5.3.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions