mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-11 05:06:51 +00:00
fix(GODT-2500): Recover in deferred function.
This commit is contained in:
@ -70,7 +70,7 @@ type Service struct { // nolint:structcheck
|
||||
eventQueue []*StreamEvent
|
||||
eventQueueMutex sync.Mutex
|
||||
|
||||
panicHandler CrashHandler
|
||||
panicHandler async.PanicHandler
|
||||
restarter Restarter
|
||||
bridge *bridge.Bridge
|
||||
eventCh <-chan events.Event
|
||||
@ -97,7 +97,7 @@ type Service struct { // nolint:structcheck
|
||||
|
||||
// NewService returns a new instance of the service.
|
||||
func NewService(
|
||||
panicHandler CrashHandler,
|
||||
panicHandler async.PanicHandler,
|
||||
restarter Restarter,
|
||||
locations service.Locator,
|
||||
bridge *bridge.Bridge,
|
||||
@ -192,10 +192,6 @@ func NewService(
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *Service) handlePanic() {
|
||||
async.HandlePanic(s.panicHandler)
|
||||
}
|
||||
|
||||
func (s *Service) initAutostart() {
|
||||
s.firstTimeAutostart.Do(func() {
|
||||
shouldAutostartBeOn := s.bridge.GetAutostart()
|
||||
@ -213,13 +209,13 @@ func (s *Service) Loop() error {
|
||||
s.log.Info("Not monitoring parent PID")
|
||||
} else {
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
s.monitorParentPID()
|
||||
}()
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
s.watchEvents()
|
||||
}()
|
||||
|
||||
@ -229,7 +225,7 @@ func (s *Service) Loop() error {
|
||||
defer close(doneCh)
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
select {
|
||||
case <-s.quitCh:
|
||||
@ -577,7 +573,7 @@ func (s *Service) monitorParentPID() {
|
||||
s.log.Info("Parent process does not exist anymore. Initiating shutdown")
|
||||
// quit will write to the parentPIDDoneCh, so we launch a goroutine.
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
if err := s.quit(); err != nil {
|
||||
logrus.WithError(err).Error("Error on quit")
|
||||
|
||||
@ -26,6 +26,7 @@ import (
|
||||
"runtime"
|
||||
|
||||
"github.com/Masterminds/semver/v3"
|
||||
"github.com/ProtonMail/gluon/async"
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/bridge"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/constants"
|
||||
@ -114,7 +115,7 @@ func (s *Service) Quit(ctx context.Context, empty *emptypb.Empty) (*emptypb.Empt
|
||||
func (s *Service) quit() error {
|
||||
// Windows is notably slow at Quitting. We do it in a goroutine to speed things up a bit.
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
if s.parentPID >= 0 {
|
||||
s.parentPIDDoneCh <- struct{}{}
|
||||
@ -223,7 +224,7 @@ func (s *Service) TriggerReset(ctx context.Context, _ *emptypb.Empty) (*emptypb.
|
||||
s.log.Debug("TriggerReset")
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
s.triggerReset()
|
||||
}()
|
||||
@ -319,7 +320,7 @@ func (s *Service) ReportBug(ctx context.Context, report *ReportBugRequest) (*emp
|
||||
}).Debug("ReportBug")
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
defer func() { _ = s.SendEvent(NewReportBugFinishedEvent()) }()
|
||||
|
||||
@ -348,7 +349,7 @@ func (s *Service) ExportTLSCertificates(_ context.Context, folderPath *wrappersp
|
||||
s.log.WithField("folderPath", folderPath).Info("ExportTLSCertificates")
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
cert, key := s.bridge.GetBridgeTLSCert()
|
||||
|
||||
@ -384,7 +385,7 @@ func (s *Service) Login(ctx context.Context, login *LoginRequest) (*emptypb.Empt
|
||||
s.log.WithField("username", login.Username).Debug("Login")
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
password, err := base64Decode(login.Password)
|
||||
if err != nil {
|
||||
@ -440,7 +441,7 @@ func (s *Service) Login2FA(ctx context.Context, login *LoginRequest) (*emptypb.E
|
||||
s.log.WithField("username", login.Username).Debug("Login2FA")
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
if s.auth.UID == "" || s.authClient == nil {
|
||||
s.log.Errorf("Login 2FA: authethication incomplete %s %p", s.auth.UID, s.authClient)
|
||||
@ -485,7 +486,7 @@ func (s *Service) Login2Passwords(ctx context.Context, login *LoginRequest) (*em
|
||||
s.log.WithField("username", login.Username).Debug("Login2Passwords")
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
password, err := base64Decode(login.Password)
|
||||
if err != nil {
|
||||
@ -507,7 +508,7 @@ func (s *Service) LoginAbort(ctx context.Context, loginAbort *LoginAbortRequest)
|
||||
s.log.WithField("username", loginAbort.Username).Debug("LoginAbort")
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
s.loginAbort()
|
||||
}()
|
||||
@ -519,7 +520,7 @@ func (s *Service) CheckUpdate(context.Context, *emptypb.Empty) (*emptypb.Empty,
|
||||
s.log.Debug("CheckUpdate")
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
updateCh, done := s.bridge.GetEvents(
|
||||
events.UpdateAvailable{},
|
||||
@ -551,7 +552,7 @@ func (s *Service) InstallUpdate(ctx context.Context, _ *emptypb.Empty) (*emptypb
|
||||
s.log.Debug("InstallUpdate")
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
safe.RLock(func() {
|
||||
s.bridge.InstallUpdate(s.target)
|
||||
@ -592,7 +593,7 @@ func (s *Service) SetDiskCachePath(ctx context.Context, newPath *wrapperspb.Stri
|
||||
s.log.WithField("path", newPath.Value).Debug("setDiskCachePath")
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
defer func() {
|
||||
_ = s.SendEvent(NewDiskCachePathChangeFinishedEvent())
|
||||
@ -659,7 +660,7 @@ func (s *Service) SetMailServerSettings(_ context.Context, settings *ImapSmtpSet
|
||||
Debug("SetConnectionMode")
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
defer func() { _ = s.SendEvent(NewChangeMailServerSettingsFinishedEvent()) }()
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ package grpc
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/ProtonMail/gluon/async"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
@ -49,7 +50,7 @@ func (s *Service) RunEventStream(request *EventStreamRequest, server Bridge_RunE
|
||||
// if events occurred before streaming started, they've been queued. Now that the stream channel is available
|
||||
// we can flush the queued
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
s.eventQueueMutex.Lock()
|
||||
defer s.eventQueueMutex.Unlock()
|
||||
|
||||
@ -20,6 +20,7 @@ package grpc
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/ProtonMail/gluon/async"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/vault"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@ -70,7 +71,7 @@ func (s *Service) SetUserSplitMode(ctx context.Context, splitMode *UserSplitMode
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
defer func() { _ = s.SendEvent(NewUserToggleSplitModeFinishedEvent(splitMode.UserID)) }()
|
||||
|
||||
var targetMode vault.AddressMode
|
||||
@ -121,7 +122,7 @@ func (s *Service) LogoutUser(ctx context.Context, userID *wrapperspb.StringValue
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
if err := s.bridge.LogoutUser(context.Background(), userID.Value); err != nil {
|
||||
s.log.WithError(err).Error("Failed to log user out")
|
||||
@ -135,7 +136,7 @@ func (s *Service) RemoveUser(ctx context.Context, userID *wrapperspb.StringValue
|
||||
s.log.WithField("UserID", userID.Value).Debug("RemoveUser")
|
||||
|
||||
go func() {
|
||||
defer s.handlePanic()
|
||||
defer async.HandlePanic(s.panicHandler)
|
||||
|
||||
// remove preferences
|
||||
if err := s.bridge.DeleteUser(context.Background(), userID.Value); err != nil {
|
||||
|
||||
@ -17,10 +17,6 @@
|
||||
|
||||
package grpc
|
||||
|
||||
type CrashHandler interface {
|
||||
HandlePanic()
|
||||
}
|
||||
|
||||
type Restarter interface {
|
||||
Set(restart, crash bool)
|
||||
AddFlags(flags ...string)
|
||||
|
||||
Reference in New Issue
Block a user