Skip to content

Commit 46b2960

Browse files
committed
fix signature and make statement watchCancel similar to connection
1 parent 5154034 commit 46b2960

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

conn_go18.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,14 @@ func (st *stmt) watchCancel(ctx context.Context) func() {
194194
go func() {
195195
select {
196196
case <-done:
197-
_ = st.cancel()
197+
// At this point the function level context is canceled,
198+
// so it must not be used for the additional network
199+
// request to cancel the query.
200+
// Create a new context to pass into the dial.
201+
ctxCancel, cancel := context.WithTimeout(context.Background(), time.Second*10)
202+
defer cancel()
203+
204+
_ = st.cancel(ctxCancel)
198205
finished <- struct{}{}
199206
case <-finished:
200207
}
@@ -209,6 +216,6 @@ func (st *stmt) watchCancel(ctx context.Context) func() {
209216
return nil
210217
}
211218

212-
func (st *stmt) cancel() error {
213-
return st.cn.cancel()
219+
func (st *stmt) cancel(ctx context.Context) error {
220+
return st.cn.cancel(ctx)
214221
}

0 commit comments

Comments
 (0)