Wrap stdlib Conn.Close() and Stmt.Close() with default 5 seconds timeout.

pull/734/head
georgysavva 2020-05-02 16:57:39 +03:00
parent e5920c3ad9
commit e27a6e71b5
1 changed files with 6 additions and 2 deletions

View File

@ -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 {