Skip to content

Commit aed1017

Browse files
committed
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
1 parent 984082b commit aed1017

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

main.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func subcmdRun() (ferr error) {
9797
var createError error
9898
CREATE_LOOP:
9999
for {
100+
debugf("start of create loop")
100101
select {
101102
case <-createExit:
102103
debugf("gracefully exiting snapshot creation goroutine")
@@ -106,8 +107,18 @@ func subcmdRun() (ferr error) {
106107
sn, err := createSnapshot(lastGood)
107108
if err != nil || sn == nil {
108109
debugf("snapshot creation finally failed (%s), the partial transfer will hopefully be reused", err)
109-
//createError = err
110-
//go func() { createExit <- true; return }()
110+
createError = err
111+
go func() {
112+
// need to stop the lastGoodTicker here because it could
113+
// happen that it will be faster and the create loop would
114+
// run again instead of exiting
115+
lastGoodOut = nil
116+
debugf("subcmdRun: sending createExit")
117+
createExit <- true
118+
debugf("subcmdRun: createExit sent")
119+
return
120+
}()
121+
time.Sleep(time.Second)
111122
}
112123
lastGoodIn <- sn
113124
debugf("pruning")
@@ -187,7 +198,9 @@ func subcmdRun() (ferr error) {
187198
createExit <- true
188199
ferr = <-createExitDone
189200
}
201+
// ferr will hold the error that happened in the CREATE_LOOP
190202
case ferr = <-createExitDone:
203+
log.Println("-> Rsync exit")
191204
}
192205
return
193206
}

rsync.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package main
66

77
import (
88
"errors"
9+
"fmt"
910
"log"
1011
"os"
1112
"os/exec"
@@ -72,7 +73,8 @@ func createSnapshot(base *snapshot) (*snapshot, error) {
7273
cmd := createRsyncCommand(newSn, base)
7374
done, err := runRsyncCommand(cmd)
7475
if err != nil {
75-
log.Fatalln("could not start rsync command:", err)
76+
log.Println("could not start rsync command:", err)
77+
return nil, err
7678
}
7779
debugf("rsync started")
7880
sigc := make(chan os.Signal, 1)
@@ -113,7 +115,7 @@ func createSnapshot(base *snapshot) (*snapshot, error) {
113115
}
114116
}
115117
if failed {
116-
return nil, err
118+
return nil, fmt.Errorf("rsync failed: %s", err)
117119
}
118120
}
119121
newSn.transComplete(cl)

0 commit comments

Comments
 (0)