Skip to content

Commit

Permalink
fix: Do not close connection twice in DigestWithOptions (#21659) (#21662
Browse files Browse the repository at this point in the history
)

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 #21656

(cherry picked from commit bce6553)

Closes #21660
  • Loading branch information
davidby-influx authored Jun 10, 2021
1 parent 23547fe commit 5251c85
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 @@ -31,6 +31,7 @@ This release adds an embedded SQLite database for storing metadata required by t

1. [21610](https://github.com/influxdata/influxdb/pull/21610): Avoid rewriting `fields.idx` unnecessarily.
1. [21648](https://github.com/influxdata/influxdb/pull/21648): Change static legend's `hide` to `show` to let users decide if they want it.
1. [21662](https://github.com/influxdata/influxdb/pull/21662): Do not close connection twice in DigestWithOptions

## v2.0.7 [2021-06-04]

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 5251c85

Please sign in to comment.