lib/model, lib/util: Replace IsComplete with NoRestartErr (ref #6947) (#7126)

This commit is contained in:
Simon Frei 2020-11-18 13:43:57 +01:00 committed by GitHub
parent 53fd54e308
commit e11b309379
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 12 deletions

View File

@ -18,6 +18,7 @@ import (
"github.com/syncthing/syncthing/lib/db"
"github.com/syncthing/syncthing/lib/events"
"github.com/syncthing/syncthing/lib/protocol"
"github.com/syncthing/syncthing/lib/util"
)
type indexSender struct {
@ -34,11 +35,12 @@ type indexSender struct {
resumeChan chan *db.FileSet
}
func (s *indexSender) Serve(ctx context.Context) error {
var err error
func (s *indexSender) Serve(ctx context.Context) (err error) {
l.Debugf("Starting indexSender for %s to %s at %s (slv=%d)", s.folder, s.conn.ID(), s.conn, s.prevSequence)
defer l.Debugf("Exiting indexSender for %s to %s at %s: %v", s.folder, s.conn.ID(), s.conn, err)
defer func() {
err = util.NoRestartErr(err)
l.Debugf("Exiting indexSender for %s to %s at %s: %v", s.folder, s.conn.ID(), s.conn, err)
}()
// We need to send one index, regardless of whether there is something to send or not
err = s.sendIndexTo(ctx)
@ -94,16 +96,9 @@ func (s *indexSender) Serve(ctx context.Context) error {
time.Sleep(250 * time.Millisecond)
}
return nil
return err
}
// Complete implements the suture.IsCompletable interface. When Serve terminates
// before Stop is called, the supervisor will check for this method and if it
// returns true removes the service instead of restarting it. Here it always
// returns true, as indexSender only terminates when a connection is
// closed/has failed, in which case retrying doesn't help.
func (s *indexSender) Complete() bool { return true }
func (s *indexSender) resume(fset *db.FileSet) {
select {
case <-s.connClosed:
@ -286,6 +281,8 @@ func (r *indexSenderRegistry) addLocked(folder config.FolderConfiguration, fset
// them. We'll start with a full index transfer.
l.Infof("Device %v folder %s has mismatching index ID for us (%v != %v)", r.deviceID, folder.Description(), startInfo.local.IndexID, myIndexID)
startSequence = 0
} else {
l.Debugf("Device %v folder %s is not delta index compatible", r.deviceID, folder.Description())
}
// This is the other side's description of themselves. We

View File

@ -246,6 +246,31 @@ func (e *FatalErr) Is(target error) bool {
return target == suture.ErrTerminateSupervisorTree
}
// NoRestartErr wraps the given error err (which may be nil) to make sure that
// `errors.Is(err, suture.ErrDoNotRestart) == true`.
func NoRestartErr(err error) error {
if err == nil {
return suture.ErrDoNotRestart
}
return &noRestartErr{err}
}
type noRestartErr struct {
err error
}
func (e *noRestartErr) Error() string {
return e.err.Error()
}
func (e *noRestartErr) Unwrap() error {
return e.err
}
func (e *noRestartErr) Is(target error) bool {
return target == suture.ErrDoNotRestart
}
type ExitStatus int
const (