diff --git a/backend/pkg/db/postgres/connector.go b/backend/pkg/db/postgres/connector.go index 37e09f812..0c0b73341 100644 --- a/backend/pkg/db/postgres/connector.go +++ b/backend/pkg/db/postgres/connector.go @@ -8,6 +8,11 @@ import ( "github.com/jackc/pgx/v4/pgxpool" ) +func getTimeoutContext() context.Context { + ctx, _ := context.WithTimeout(context.Background(), time.Duration(time.Second*10)) + return ctx +} + type Conn struct { c *pgxpool.Pool // TODO: conditional usage of Pool/Conn (use interface?) } @@ -26,15 +31,15 @@ func (conn *Conn) Close() error { } func (conn *Conn) query(sql string, args ...interface{}) (pgx.Rows, error) { - return conn.c.Query(context.Background(), sql, args...) + return conn.c.Query(getTimeoutContext(), sql, args...) } func (conn *Conn) queryRow(sql string, args ...interface{}) pgx.Row { - return conn.c.QueryRow(context.Background(), sql, args...) + return conn.c.QueryRow(getTimeoutContext(), sql, args...) } func (conn *Conn) exec(sql string, args ...interface{}) error { - _, err := conn.c.Exec(context.Background(), sql, args...) + _, err := conn.c.Exec(getTimeoutContext(), sql, args...) return err }