Ограничить дозвон и поиск имени зависимостей одной секундой
This commit is contained in:
@@ -26,7 +26,7 @@ import (
|
||||
|
||||
const (
|
||||
maxConns = 10
|
||||
connectTimeout = 3 * time.Second
|
||||
connectTimeout = time.Second
|
||||
statementTimeout = 5 * time.Second
|
||||
idleInTxTimeout = 10 * time.Second
|
||||
)
|
||||
@@ -40,6 +40,14 @@ func NewPool(ctx context.Context, dsn string) (*pgxpool.Pool, error) {
|
||||
}
|
||||
cfg.MaxConns = maxConns
|
||||
cfg.ConnConfig.ConnectTimeout = connectTimeout
|
||||
// pgconn applies ConnectTimeout to dialling but resolves the host name
|
||||
// before that with the caller's context. Docker DNS takes seconds to give
|
||||
// up on a stopped container, so the lookup gets the same bound.
|
||||
cfg.ConnConfig.LookupFunc = func(ctx context.Context, host string) ([]string, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, connectTimeout)
|
||||
defer cancel()
|
||||
return net.DefaultResolver.LookupHost(ctx, host)
|
||||
}
|
||||
cfg.ConnConfig.RuntimeParams["statement_timeout"] = strconv.FormatInt(statementTimeout.Milliseconds(), 10)
|
||||
cfg.ConnConfig.RuntimeParams["idle_in_transaction_session_timeout"] = strconv.FormatInt(idleInTxTimeout.Milliseconds(), 10)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user