From e27a6e71b59f23fac7abcc4eb762e99c25fd4fd1 Mon Sep 17 00:00:00 2001 From: georgysavva Date: Sat, 2 May 2020 16:57:39 +0300 Subject: [PATCH] Wrap stdlib Conn.Close() and Stmt.Close() with default 5 seconds timeout. --- stdlib/sql.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stdlib/sql.go b/stdlib/sql.go index 8ff3fd49..eb0ec9ac 100644 --- a/stdlib/sql.go +++ b/stdlib/sql.go @@ -225,7 +225,9 @@ func (c *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, e } func (c *Conn) Close() error { - return c.conn.Close(context.Background()) + ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) + defer cancel() + return c.conn.Close(ctx) } func (c *Conn) Begin() (driver.Tx, error) { @@ -325,7 +327,9 @@ type Stmt struct { } func (s *Stmt) Close() error { - return s.conn.conn.Deallocate(context.Background(), s.sd.Name) + ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) + defer cancel() + return s.conn.conn.Deallocate(ctx, s.sd.Name) } func (s *Stmt) NumInput() int {