Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #16 from vshn/debug_raceconditions
Browse files Browse the repository at this point in the history
This commit fixes a racecondition that was causing hangs during backups
on a few clusters. Also added the `--race` flag to the automated
integration test, to detect if new race conditions are introduced in new
releases.
  • Loading branch information
Kidswiss authored Jan 3, 2020
2 parents 6f97bc4 + a1de025 commit c97a03e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"go.testTimeout": "120s",
"go.testFlags": [
"-v",
"--race",
],
"go.testEnvVars": {
"RESTIC_REPOSITORY":"s3:http://localhost:9000/baas1",
Expand Down
23 changes: 17 additions & 6 deletions restic/genericCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (g *genericCommand) exec(args []string, options commandOptions) {
commandStderr, err := cmd.StderrPipe()

finished := make(chan error, 0)
defer close(finished)

err = cmd.Start()
if err != nil {
Expand All @@ -103,18 +104,20 @@ func (g *genericCommand) exec(args []string, options commandOptions) {

go func() {
var collectErr error
stdOut, collectErr := g.collectOutput(commandStdout, options.print, options.output)
finished <- collectErr
g.mutex.Lock()
g.stdOut, collectErr = g.collectOutput(commandStdout, options.print, options.output)
g.stdOut = stdOut
g.mutex.Unlock()
finished <- collectErr
}()

go func() {
var collectErr error
stdErr, collectErr := g.collectOutput(commandStderr, options.print, options.output)
finished <- collectErr
g.mutex.Lock()
g.stdErrOut, collectErr = g.collectOutput(commandStderr, options.print, options.output)
g.stdErrOut = stdErr
g.mutex.Unlock()
finished <- collectErr
}()

collectErr1 := <-finished
Expand Down Expand Up @@ -161,10 +164,18 @@ func (g *genericCommand) collectOutput(output io.Reader, print bool, out chan st
func (g *genericCommand) GetError() error { return g.errorMessage }

// GetStdOut returns the complete output of the command
func (g *genericCommand) GetStdOut() []string { return g.stdOut }
func (g *genericCommand) GetStdOut() []string {
g.mutex.Lock()
defer g.mutex.Unlock()
return g.stdOut
}

// GetStdErrOut returns the complete StdErr of the command
func (g *genericCommand) GetStdErrOut() []string { return g.stdErrOut }
func (g *genericCommand) GetStdErrOut() []string {
g.mutex.Lock()
defer g.mutex.Unlock()
return g.stdErrOut
}

// GetWebhookData returns all objects that should get marshalled to json and
// sent to the webhook endpoint. Returns nil by default.
Expand Down
6 changes: 3 additions & 3 deletions restic/listsnapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ func (l *ListSnapshotsStruct) ListSnapshots(last bool) []Snapshot {

l.genericCommand.exec(args, commandOptions{print: false})
fmt.Printf("Listing snapshots\n")
if len(l.stdErrOut) > 1 && strings.Contains(l.stdErrOut[1], "following location?") {
if len(l.GetStdErrOut()) > 1 && strings.Contains(l.GetStdErrOut()[1], "following location?") {
l.errorMessage = errors.New(notInitialisedError)
return nil
}
snaps := make([]Snapshot, 0)
output := strings.Join(l.stdOut, "\n")
output := strings.Join(l.GetStdOut(), "\n")
err := json.Unmarshal([]byte(output), &snaps)
if err != nil {
fmt.Printf("Error listing snapshots:\n%v\n%v\n%v\n", err, output, strings.Join(l.stdErrOut, "\n"))
fmt.Printf("Error listing snapshots:\n%v\n%v\n%v\n", err, output, strings.Join(l.GetStdErrOut(), "\n"))
l.errorMessage = err
return nil
}
Expand Down

0 comments on commit c97a03e

Please sign in to comment.