GODT-1657: Stable sync (still needs more tests)

This commit is contained in:
James Houlahan
2022-10-01 23:14:42 +02:00
parent 705875cff2
commit 9d69a2e565
34 changed files with 1270 additions and 1099 deletions

View File

@ -69,6 +69,9 @@ type Bridge struct {
// errors contains errors encountered during startup.
errors []error
// stopCh is used to stop ongoing goroutines when the bridge is closed.
stopCh chan struct{}
}
// New creates a new bridge.
@ -153,6 +156,8 @@ func New(
focusService: focusService,
autostarter: autostarter,
locator: locator,
stopCh: make(chan struct{}),
}
api.AddStatusObserver(func(status liteapi.Status) {
@ -232,12 +237,8 @@ func (bridge *Bridge) GetErrors() []error {
}
func (bridge *Bridge) Close(ctx context.Context) error {
// Abort any ongoing syncs.
for _, user := range bridge.users {
if err := user.AbortSync(ctx); err != nil {
return fmt.Errorf("failed to abort sync: %w", err)
}
}
// Stop ongoing operations such as connectivity checks.
close(bridge.stopCh)
// Close the IMAP server.
if err := bridge.closeIMAP(ctx); err != nil {
@ -251,7 +252,7 @@ func (bridge *Bridge) Close(ctx context.Context) error {
// Close all users.
for _, user := range bridge.users {
if err := user.Close(ctx); err != nil {
if err := user.Close(); err != nil {
logrus.WithError(err).Error("Failed to close user")
}
}
@ -335,6 +336,9 @@ func (bridge *Bridge) onStatusDown() {
case <-upCh:
return
case <-bridge.stopCh:
return
case <-time.After(backoff):
if err := bridge.api.Ping(ctx); err != nil {
logrus.WithError(err).Debug("Failed to ping API")