Skip to content

Commit c6a571f

Browse files
ensure proper closure of resp.Body in error handling and empty response cases in datasource.go to prevent resource leak (#537)
1 parent 4144bfe commit c6a571f

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## tip
44

5+
* BUGFIX: fix closing connections in the datasource backend to prevent resource leak. See [pr #537](https://github.com/VictoriaMetrics/victorialogs-datasource/pull/537).
6+
57
## v0.23.4
68

79
* BUGFIX: update dependencies to fix security issues with react-router. See [pr #534](https://github.com/VictoriaMetrics/victorialogs-datasource/pull/534).

pkg/plugin/datasource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ func (di *DatasourceInstance) datasourceQuery(ctx context.Context, q *Query, isS
413413
}
414414

415415
if resp.StatusCode != http.StatusOK {
416+
defer resp.Body.Close()
417+
416418
switch resp.StatusCode {
417419
case http.StatusUnprocessableEntity:
418420
return nil, parseErrorResponse(resp.Body)
@@ -426,6 +428,7 @@ func (di *DatasourceInstance) datasourceQuery(ctx context.Context, q *Query, isS
426428
// This is to handle cases where VictoriaLogs returns no data
427429
// and avoid json decoding errors
428430
if resp.ContentLength == 0 {
431+
resp.Body.Close()
429432
return nil, nil
430433
}
431434

0 commit comments

Comments
 (0)