Skip to content

Commit

Permalink
fix: Do not close connection twice in DigestWithOptions (influxdata#2…
Browse files Browse the repository at this point in the history
…1659)

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 influxdata#21656
  • Loading branch information
davidby-influx authored and chengshiwen committed Aug 27, 2024
1 parent a58ee5f commit 9fbd792
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
-------------------
Expand Down
14 changes: 10 additions & 4 deletions tsdb/engine/tsm1/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
}()

Expand All @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 9fbd792

Please sign in to comment.