mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-11 05:06:51 +00:00
GODT-1657: Stable sync (still needs more tests)
This commit is contained in:
@ -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")
|
||||
|
||||
Reference in New Issue
Block a user