Skip to content

Commit c2ac4bf

Browse files
authored
fix: panic on query canceled (#168)
1 parent cf3760d commit c2ac4bf

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.2
1+
0.8.3

client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,8 @@ func (c *APIClient) applySessionState(response *QueryResponse) {
414414
}
415415

416416
func (c *APIClient) PollUntilQueryEnd(ctx context.Context, resp *QueryResponse) (*QueryResponse, error) {
417-
var err error
418417
for !resp.ReadFinished() {
419-
data := resp.Data
420-
resp, err = c.PollQuery(ctx, resp.NextURI)
418+
nextResponse, err := c.PollQuery(ctx, resp.NextURI)
421419
if err != nil {
422420
if errors.Is(err, context.Canceled) {
423421
// context might be canceled due to timeout or canceled. if it's canceled, we need call
@@ -427,6 +425,8 @@ func (c *APIClient) PollUntilQueryEnd(ctx context.Context, resp *QueryResponse)
427425
}
428426
return nil, err
429427
}
428+
data := resp.Data
429+
resp = nextResponse
430430
if resp.Error != nil {
431431
return nil, errors.Wrap(resp.Error, "query page has error")
432432
}

rows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ func waitForData(ctx context.Context, dc *DatabendConn, response *QueryResponse)
3030
if response.Error != nil {
3131
return nil, response.Error
3232
}
33-
var err error
3433
for !response.ReadFinished() && len(response.Data) == 0 && response.Error == nil {
35-
response, err = dc.rest.PollQuery(ctx, response.NextURI)
34+
nextResponse, err := dc.rest.PollQuery(ctx, response.NextURI)
3635
if err != nil {
3736
if errors.Is(err, context.Canceled) {
3837
// context might be canceled due to timeout or canceled. if it's canceled, we need call
@@ -44,6 +43,7 @@ func waitForData(ctx context.Context, dc *DatabendConn, response *QueryResponse)
4443
}
4544
return nil, err
4645
}
46+
response = nextResponse
4747
if response.Error != nil {
4848
_ = dc.rest.CloseQuery(ctx, response)
4949
return nil, fmt.Errorf("query error: %+v", response.Error)

0 commit comments

Comments
 (0)