From cc8aaba52acabf77ab6ae06d64f02ee734c98881 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Thu, 21 Sep 2023 00:12:12 +0200 Subject: [PATCH 1/4] reduced a few loglevels to test if they are the reason why our serer keeps crashlooping --- .../ios_apns/iosAPNsRepository.go | 2 +- server/backend/rpcserver.go | 2 +- server/main.go | 15 ++++++--------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/server/backend/ios_notifications/ios_apns/iosAPNsRepository.go b/server/backend/ios_notifications/ios_apns/iosAPNsRepository.go index 05c03edb..339c4019 100644 --- a/server/backend/ios_notifications/ios_apns/iosAPNsRepository.go +++ b/server/backend/ios_notifications/ios_apns/iosAPNsRepository.go @@ -140,7 +140,7 @@ func NewCronRepository(db *gorm.DB) (*Repository, error) { token, err := ios_apns_jwt.NewToken() if err != nil { - log.WithError(err).Fatal("Could not create APNs token") + log.WithError(err).Error("Could not create APNs token") } return NewRepository(db, token), nil diff --git a/server/backend/rpcserver.go b/server/backend/rpcserver.go index 5f275b36..fa26e1ed 100644 --- a/server/backend/rpcserver.go +++ b/server/backend/rpcserver.go @@ -61,7 +61,7 @@ func NewIOSNotificationsService() *IOSNotificationsService { token, err := ios_apns_jwt.NewToken() if err != nil { - log.WithError(err).Fatal("failed to create new token") + log.WithError(err).Error("failed to create new token") } return &IOSNotificationsService{ diff --git a/server/main.go b/server/main.go index 9e624b66..8481f15d 100644 --- a/server/main.go +++ b/server/main.go @@ -108,7 +108,7 @@ func main() { grpc.WithUnaryInterceptor(addMethodNameInterceptor), } if err := pb.RegisterCampusHandlerFromEndpoint(context.Background(), grpcGatewayMux, httpPort, opts); err != nil { - log.WithError(err).Panic("could not RegisterCampusHandlerFromEndpoint") + log.WithError(err).Fatal("could not RegisterCampusHandlerFromEndpoint") } httpMux.Handle("/v1/", http.StripPrefix("/v1", grpcGatewayMux)) @@ -128,18 +128,15 @@ func main() { // setupDB connects to the database and migrates it if necessary func setupDB() *gorm.DB { - // Connect to DB - var conn gorm.Dialector - if dbHost := os.Getenv("DB_DSN"); dbHost == "" { + dbHost := os.Getenv("DB_DSN") + if dbHost == "" { log.Fatal("Failed to start! The 'DB_DSN' environment variable is not defined. Take a look at the README.md for more details.") - } else { - log.Info("Connecting to dsn") - conn = mysql.Open(dbHost) } - db, err := gorm.Open(conn, &gorm.Config{Logger: gorm_logrus.New()}) + log.Info("Connecting to dsn") + db, err := gorm.Open(mysql.Open(dbHost), &gorm.Config{Logger: gorm_logrus.New()}) if err != nil { - log.WithError(err).Panic("failed to connect database") + log.WithError(err).Fatal("failed to connect database") } // Migrate the schema From 73df1e4061c8ad5c839810add85861bffa1404cb Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Thu, 21 Sep 2023 00:30:17 +0200 Subject: [PATCH 2/4] fixed the device-flushing interval not being const --- server/backend/device.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/server/backend/device.go b/server/backend/device.go index 0250f4e7..3ab3068b 100644 --- a/server/backend/device.go +++ b/server/backend/device.go @@ -18,23 +18,22 @@ import ( // deviceBuffer stores all recent device calls in a buffer and flushes them to the database periodically type deviceBuffer struct { - lock sync.Mutex - devices map[string]*model.Devices // key is uuid - interval time.Duration // flush interval + lock sync.Mutex + devices map[string]*model.Devices // key is uuid } func newDeviceBuffer() *deviceBuffer { return &deviceBuffer{ - lock: sync.Mutex{}, - devices: make(map[string]*model.Devices), - interval: time.Minute, + lock: sync.Mutex{}, + devices: make(map[string]*model.Devices), } - } +const FlushingInterval = time.Minute + func (s *CampusServer) RunDeviceFlusher() error { for { - time.Sleep(s.deviceBuf.interval) + time.Sleep(FlushingInterval) if err := s.deviceBuf.flush(s.db); err != nil { log.WithError(err).Error("Error flushing device buffer") } From c50d0292f7bf81ed33df6e0ab7876780bae301c7 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Thu, 21 Sep 2023 21:52:19 +0200 Subject: [PATCH 3/4] versioned the client correctly --- client/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/go.mod b/client/go.mod index 86ba0792..6bf58f57 100644 --- a/client/go.mod +++ b/client/go.mod @@ -3,7 +3,7 @@ module github.com/TUM-Dev/Campus-Backend/client go 1.21 require ( - github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230919222217-aae98ca6718a + github.com/TUM-Dev/Campus-Backend/server v0.8.0 github.com/sirupsen/logrus v1.9.3 google.golang.org/grpc v1.58.1 ) From 301a0c7bab9836fe49d053316c1f5075e5697a43 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Thu, 21 Sep 2023 22:09:00 +0200 Subject: [PATCH 4/4] Revert "versioned the client correctly" This reverts commit c50d0292 --- client/go.mod | 2 +- client/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/go.mod b/client/go.mod index 6bf58f57..0b101708 100644 --- a/client/go.mod +++ b/client/go.mod @@ -3,7 +3,7 @@ module github.com/TUM-Dev/Campus-Backend/client go 1.21 require ( - github.com/TUM-Dev/Campus-Backend/server v0.8.0 + github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230920223017-73df1e4061c8 github.com/sirupsen/logrus v1.9.3 google.golang.org/grpc v1.58.1 ) diff --git a/client/go.sum b/client/go.sum index 3579b6c4..72830782 100644 --- a/client/go.sum +++ b/client/go.sum @@ -1,5 +1,5 @@ -github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230919222217-aae98ca6718a h1:liiUwphQFYkB0DeDCOX3iasHwgcUSQxEEYDohpurAI0= -github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230919222217-aae98ca6718a/go.mod h1:fjoLL3rbdY6wTRJIksekT2p3OUp5ocFfXjB/avV/TVI= +github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230920223017-73df1e4061c8 h1:FYhgX9DA9JvEyP06VX/Ot/8Oav9fS8hwHhGOyLfvX6E= +github.com/TUM-Dev/Campus-Backend/server v0.0.0-20230920223017-73df1e4061c8/go.mod h1:fjoLL3rbdY6wTRJIksekT2p3OUp5ocFfXjB/avV/TVI= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=