diff --git a/conn_go18.go b/conn_go18.go index dda7dc60..3c83082b 100644 --- a/conn_go18.go +++ b/conn_go18.go @@ -11,6 +11,10 @@ import ( "time" ) +const ( + watchCancelDialContextTimeout = time.Second * 10 +) + // Implement the "QueryerContext" interface func (cn *conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) { list := make([]driver.Value, len(args)) @@ -117,7 +121,7 @@ func (cn *conn) watchCancel(ctx context.Context) func() { // so it must not be used for the additional network // request to cancel the query. // Create a new context to pass into the dial. - ctxCancel, cancel := context.WithTimeout(context.Background(), time.Second*10) + ctxCancel, cancel := context.WithTimeout(context.Background(), watchCancelDialContextTimeout) defer cancel() _ = cn.cancel(ctxCancel) @@ -213,6 +217,7 @@ func (st *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driv return st.Exec(list) } +// watchCancel is implemented on stmt in order to not mark the parent conn as bad func (st *stmt) watchCancel(ctx context.Context) func() { if done := ctx.Done(); done != nil { finished := make(chan struct{}) @@ -223,7 +228,7 @@ func (st *stmt) watchCancel(ctx context.Context) func() { // so it must not be used for the additional network // request to cancel the query. // Create a new context to pass into the dial. - ctxCancel, cancel := context.WithTimeout(context.Background(), time.Second*10) + ctxCancel, cancel := context.WithTimeout(context.Background(), watchCancelDialContextTimeout) defer cancel() _ = st.cancel(ctxCancel)