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

TCP error on idle connection #141

Closed
imraan-go opened this issue Sep 1, 2021 · 2 comments · Fixed by #142
Closed

TCP error on idle connection #141

imraan-go opened this issue Sep 1, 2021 · 2 comments · Fixed by #142

Comments

@imraan-go
Copy link

After the connection idles for few hours, the first few request fails with TCP error:

write tcp 192.168.3.4:65383->3.1.14.XXX:5432: write: broken pipe

This is the code i'm using on startup of my application:

dsn := fmt.Sprintf("postgres://%v:%s@%v:5432/%v?sslmode=disable", dbconfig.Get("dbuser").(string), url.QueryEscape(dbconfig.Get("dbpass").(string)), dbconfig.Get("dbhost").(string), dbconfig.Get("dbname").(string))
	sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(dsn)))

	if err != nil {
		log.Fatal(err)
	}
	err = sqldb.Ping()
	if err != nil {
		log.Fatal(err)
	}

	db := bun.NewDB(sqldb, pgdialect.New())
	db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose()))

I didn't have that issue with lib/pq driver before.

@imraan-go imraan-go changed the title TCP error after on idle connection TCP error on idle connection Sep 1, 2021
@imraan-go
Copy link
Author

The fix should be similar to this: lib/pq#1013

@vmihailenco
Copy link
Member

Thanks for bringing this 👍

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

Successfully merging a pull request may close this issue.

2 participants