Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Close() method to the connector for a pooled connection #2068

Closed
markvai opened this issue Jul 2, 2024 · 3 comments
Closed

Add Close() method to the connector for a pooled connection #2068

markvai opened this issue Jul 2, 2024 · 3 comments

Comments

@markvai
Copy link

markvai commented Jul 2, 2024

Since #1718 we can use a pooled connector with sql.DB, passing a connector and using the interface.

However, when an interface user closes the connection using sql.DB.Close(), the inner logic tries to close the connector if possible:

func (db *DB) Close() error {
...
	if c, ok := db.connector.(io.Closer); ok {
		err1 := c.Close()
		...

But since the connector does not satisfy the interface, the pool is not closed and the connections leak.

The request here is to add the Close() method to the connector for cases when it has a pool, in a similar manner it branches in the func (c connector) Connect method.

@jackc
Copy link
Owner

jackc commented Jul 4, 2024

Closing the sql.DB shouldn't close the underlying pgxpool.Pool. It's entirely possible to create a pgxpool.Pool, use it to create sql.DB, close the sql.DB, and keep using the pgxpool.Pool.

@markvai
Copy link
Author

markvai commented Jul 4, 2024

@jackc
With that you are suggesting that users use both sql.DB and pgxpool.Pool for DB operations?
In the docs you specifically have a section that describes how to pick between the two when opening a new connection.
My assumption is that users that choose one don't also use the other, if that is a real use case, then I will close this issue.

@jackc
Copy link
Owner

jackc commented Jul 4, 2024

Using both together is the use case. Sometimes someone will want to use pgx directly but also use a database/sql library like gorm.

@markvai markvai closed this as completed Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants