Skip to content

Commit

Permalink
fix Close() on rows when a timeout during processing(porting ClickHou…
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-cai-timeplus committed Dec 18, 2023
1 parent c66adfd commit 22c4d2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions clickhouse_rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,26 @@ func (r *rows) Columns() []string {
}

func (r *rows) Close() error {
for range r.stream {
}
for err := range r.errors {
if err != nil {
r.err = err
active := 2
for {
select {
case _, ok := <-r.stream:
if !ok {
active--
if active == 0 {
return r.err
}
}
case err, ok := <-r.errors:
if err != nil {
r.err = err
}
if !ok {
active--
if active == 0 {
return r.err
}
}
}
}
return r.err
Expand Down
2 changes: 1 addition & 1 deletion conn_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (c *connect) query(ctx context.Context, release func(*connect, error), quer
if err != nil {
errors <- err
}
close(errors)
close(stream)
close(errors)
release(c, err)
}()

Expand Down

0 comments on commit 22c4d2d

Please sign in to comment.