mirror of https://github.com/jackc/pgx.git
Always use keep-alive on TCP conns
parent
a724d7bce6
commit
3d7974ce30
6
conn.go
6
conn.go
|
@ -28,7 +28,6 @@ type ConnConfig struct {
|
||||||
Password string
|
Password string
|
||||||
TLSConfig *tls.Config // config for TLS connection -- nil disables TLS
|
TLSConfig *tls.Config // config for TLS connection -- nil disables TLS
|
||||||
Logger Logger
|
Logger Logger
|
||||||
KeepAlive uint16 // keep-alive period for the connetion (0 disables keep-alive)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Conn is a PostgreSQL connection handle. It is not safe for concurrent usage.
|
// Conn is a PostgreSQL connection handle. It is not safe for concurrent usage.
|
||||||
|
@ -133,10 +132,7 @@ func Connect(config ConnConfig) (c *Conn, err error) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.logger.Info(fmt.Sprintf("Dialing PostgreSQL server at host: %s:%d", c.config.Host, c.config.Port))
|
c.logger.Info(fmt.Sprintf("Dialing PostgreSQL server at host: %s:%d", c.config.Host, c.config.Port))
|
||||||
var d net.Dialer
|
d := net.Dialer{KeepAlive: 5 * time.Minute}
|
||||||
if c.config.KeepAlive != 0 {
|
|
||||||
d.KeepAlive = time.Duration(c.config.KeepAlive) * time.Second
|
|
||||||
}
|
|
||||||
c.conn, err = d.Dial("tcp", fmt.Sprintf("%s:%d", c.config.Host, c.config.Port))
|
c.conn, err = d.Dial("tcp", fmt.Sprintf("%s:%d", c.config.Host, c.config.Port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Error(fmt.Sprintf("Connection failed: %v", err))
|
c.logger.Error(fmt.Sprintf("Connection failed: %v", err))
|
||||||
|
|
Loading…
Reference in New Issue