Skip to content

Commit 12eeae8

Browse files
authored
[BL-8235] Fix a connection leak in PingContext (#240)
Connection.Ping does not close the result set from query, which leads to open result set --------- Signed-off-by: Jacky Hu <[email protected]>
1 parent fe1beea commit 12eeae8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

connection.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ func (c *conn) Ping(ctx context.Context) error {
7878

7979
ctx1, cancel := context.WithTimeout(ctx, c.cfg.PingTimeout)
8080
defer cancel()
81-
_, err := c.QueryContext(ctx1, "select 1", nil)
81+
rows, err := c.QueryContext(ctx1, "select 1", nil)
8282
if err != nil {
8383
log.Err(err).Msg("databricks: failed to ping")
8484
return dbsqlerrint.NewBadConnectionError(err)
8585
}
86+
defer rows.Close()
8687

8788
log.Debug().Msg("databricks: ping successful")
8889
return nil

connection_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,9 +1370,14 @@ func TestConn_Ping(t *testing.T) {
13701370
return getOperationStatusResp, nil
13711371
}
13721372

1373+
var closeCount int
13731374
testClient := &client.TestClient{
13741375
FnExecuteStatement: executeStatement,
13751376
FnGetOperationStatus: getOperationStatus,
1377+
FnCloseOperation: func(ctx context.Context, req *cli_service.TCloseOperationReq) (_r *cli_service.TCloseOperationResp, _err error) {
1378+
closeCount++
1379+
return nil, nil
1380+
},
13761381
}
13771382

13781383
testConn := &conn{
@@ -1384,6 +1389,7 @@ func TestConn_Ping(t *testing.T) {
13841389

13851390
assert.Nil(t, err)
13861391
assert.Equal(t, 1, executeStatementCount)
1392+
assert.Equal(t, 1, closeCount)
13871393
})
13881394
}
13891395

0 commit comments

Comments
 (0)