Commit aed1017e authored by Sebastian Stark's avatar Sebastian Stark

handle rsync failure gracefully

  - main loop will now gracefully exit when rsync is not found or
  returns anything except 0 or 24.
  - pid unlock works now in this case
  - probably we will need to handle other rsync return codes like 24
parent 984082bc
......@@ -97,6 +97,7 @@ func subcmdRun() (ferr error) {
var createError error
CREATE_LOOP:
for {
debugf("start of create loop")
select {
case <-createExit:
debugf("gracefully exiting snapshot creation goroutine")
......@@ -106,8 +107,18 @@ func subcmdRun() (ferr error) {
sn, err := createSnapshot(lastGood)
if err != nil || sn == nil {
debugf("snapshot creation finally failed (%s), the partial transfer will hopefully be reused", err)
//createError = err
//go func() { createExit <- true; return }()
createError = err
go func() {
// need to stop the lastGoodTicker here because it could
// happen that it will be faster and the create loop would
// run again instead of exiting
lastGoodOut = nil
debugf("subcmdRun: sending createExit")
createExit <- true
debugf("subcmdRun: createExit sent")
return
}()
time.Sleep(time.Second)
}
lastGoodIn <- sn
debugf("pruning")
......@@ -187,7 +198,9 @@ func subcmdRun() (ferr error) {
createExit <- true
ferr = <-createExitDone
}
// ferr will hold the error that happened in the CREATE_LOOP
case ferr = <-createExitDone:
log.Println("-> Rsync exit")
}
return
}
......
......@@ -6,6 +6,7 @@ package main
import (
"errors"
"fmt"
"log"
"os"
"os/exec"
......@@ -72,7 +73,8 @@ func createSnapshot(base *snapshot) (*snapshot, error) {
cmd := createRsyncCommand(newSn, base)
done, err := runRsyncCommand(cmd)
if err != nil {
log.Fatalln("could not start rsync command:", err)
log.Println("could not start rsync command:", err)
return nil, err
}
debugf("rsync started")
sigc := make(chan os.Signal, 1)
......@@ -113,7 +115,7 @@ func createSnapshot(base *snapshot) (*snapshot, error) {
}
}
if failed {
return nil, err
return nil, fmt.Errorf("rsync failed: %s", err)
}
}
newSn.transComplete(cl)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment