From 9fbd79295be4c4646ece100b37628aa3721272ca Mon Sep 17 00:00:00 2001 From: davidby-influx <72418212+davidby-influx@users.noreply.github.com> Date: Thu, 10 Jun 2021 12:41:42 -0700 Subject: [PATCH] fix: Do not close connection twice in DigestWithOptions (#21659) tsm1.DigestWithOptions closes its network connection twice. This may cause broken pipe errors on concurrent invocations of the same procedure, by closing a reused i/o descriptor. This fix also captures errors from TSM file closures, which were previously ignored. Closes https://github.com/influxdata/influxdb/issues/21656 --- CHANGELOG.md | 1 + tsdb/engine/tsm1/digest.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6a36a9fb2b..a72195e42bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ v1.8.11 [unreleased] - [#18429](https://github.com/influxdata/influxdb/pull/18429): Add option to authenticate prometheus remote read - [#21592](https://github.com/influxdata/influxdb/pull/21592): fix: avoid rewriting fields.idx unnecessarily +- [#21659](https://github.com/influxdata/influxdb/pull/21659): fix: do not close connection twice in DigestWithOptions v1.8.10 [2021-10-11] ------------------- diff --git a/tsdb/engine/tsm1/digest.go b/tsdb/engine/tsm1/digest.go index c4613d0b48a..d66dc9fb343 100644 --- a/tsdb/engine/tsm1/digest.go +++ b/tsdb/engine/tsm1/digest.go @@ -22,7 +22,7 @@ type DigestOptions struct { // DigestWithOptions writes a digest of dir to w using options to filter by // time and key range. -func DigestWithOptions(dir string, files []string, opts DigestOptions, w io.WriteCloser) error { +func DigestWithOptions(dir string, files []string, opts DigestOptions, w io.WriteCloser) (err error) { manifest, err := NewDigestManifest(dir, files) if err != nil { return err @@ -31,7 +31,9 @@ func DigestWithOptions(dir string, files []string, opts DigestOptions, w io.Writ tsmFiles := make([]TSMFile, 0, len(files)) defer func() { for _, r := range tsmFiles { - r.Close() + if e := r.Close(); e != nil && err == nil { + err = e + } } }() @@ -54,7 +56,11 @@ func DigestWithOptions(dir string, files []string, opts DigestOptions, w io.Writ if err != nil { return err } - defer dw.Close() + defer func() { + if e := dw.Close(); e != nil && err == nil { + err = e + } + }() // Write the manifest. if err := dw.WriteManifest(manifest); err != nil { @@ -106,7 +112,7 @@ func DigestWithOptions(dir string, files []string, opts DigestOptions, w io.Writ return err } } - return dw.Close() + return nil } // Digest writes a digest of dir to w of a full shard dir.