Skip to content

Commit 01b7c29

Browse files
authored
properly close io.ReadCloser to avoid memory leak (#280)
cleanup
1 parent 4b654b7 commit 01b7c29

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
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: properly close io.ReadCloser to avoid memory leak. See [this pull request](https://github.com/VictoriaMetrics/victorialogs-datasource/pull/280).
6+
57
## v0.16.1
68

79
* BUGFIX: fix log context in dashboard view. See [this pull request](https://github.com/VictoriaMetrics/victorialogs-datasource/pull/267).

pkg/plugin/datasource.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ func (d *Datasource) streamQuery(ctx context.Context, request *backend.RunStream
231231
return err
232232
}
233233

234+
defer func() {
235+
if err := r.Close(); err != nil {
236+
backend.Logger.Error("failed to close response body", "err", err.Error())
237+
}
238+
}()
239+
234240
ch, ok := d.liveModeResponses.Load(request.Path)
235241
if !ok {
236242
return fmt.Errorf("failed to find the channel for the query: %s", request.Path)
@@ -310,7 +316,7 @@ func (d *Datasource) query(ctx context.Context, _ backend.PluginContext, q *Quer
310316

311317
defer func() {
312318
if err := r.Close(); err != nil {
313-
log.DefaultLogger.Error("failed to close response body", "err", err.Error())
319+
backend.Logger.Error("failed to close response body", "err", err.Error())
314320
}
315321
}()
316322

0 commit comments

Comments
 (0)