From 339c5bae769566d7295d7e8c26cfd4523d5030e2 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Tue, 4 Aug 2020 09:16:20 +0530 Subject: [PATCH] MM-26836: Remove some app fields which cause race conditions (#15019) `(a *App) InitServer` was being called from multiple goroutines and were modifying the fields of the App struct concurrently. However, the fields were just reflecting the Server fields, and we already have public getters for those fields. Therefore, we remove those fields and just change the code to return the server field directly. Co-authored-by: Mattermod --- app/app.go | 32 ++++++++++---------------------- app/options.go | 1 - 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/app/app.go b/app/app.go index facbe2c5b1..5998105200 100644 --- a/app/app.go +++ b/app/app.go @@ -38,16 +38,12 @@ type App struct { userAgent string acceptLanguage string - accountMigration einterfaces.AccountMigrationInterface - cluster einterfaces.ClusterInterface - compliance einterfaces.ComplianceInterface - dataRetention einterfaces.DataRetentionInterface - searchEngine *searchengine.Broker - ldap einterfaces.LdapInterface - messageExport einterfaces.MessageExportInterface - metrics einterfaces.MetricsInterface - notification einterfaces.NotificationInterface - saml einterfaces.SamlInterface + cluster einterfaces.ClusterInterface + compliance einterfaces.ComplianceInterface + dataRetention einterfaces.DataRetentionInterface + searchEngine *searchengine.Broker + messageExport einterfaces.MessageExportInterface + metrics einterfaces.MetricsInterface httpService httpservice.HTTPService imageProxy *imageproxy.ImageProxy @@ -69,10 +65,6 @@ func New(options ...AppOption) *App { func (a *App) InitServer() { a.srv.AppInitializedOnce.Do(func() { a.initEnterprise() - a.accountMigration = a.srv.AccountMigration - a.ldap = a.srv.Ldap - a.notification = a.srv.Notification - a.saml = a.srv.Saml a.AddConfigListener(func(oldConfig *model.Config, newConfig *model.Config) { if *oldConfig.GuestAccountsSettings.Enable && !*newConfig.GuestAccountsSettings.Enable { @@ -116,10 +108,6 @@ func (a *App) InitServer() { } a.srv.RunJobs() }) - a.accountMigration = a.srv.AccountMigration - a.ldap = a.srv.Ldap - a.notification = a.srv.Notification - a.saml = a.srv.Saml } func (a *App) initJobs() { @@ -467,7 +455,7 @@ func (a *App) AcceptLanguage() string { return a.acceptLanguage } func (a *App) AccountMigration() einterfaces.AccountMigrationInterface { - return a.accountMigration + return a.srv.AccountMigration } func (a *App) Cluster() einterfaces.ClusterInterface { return a.cluster @@ -482,7 +470,7 @@ func (a *App) SearchEngine() *searchengine.Broker { return a.searchEngine } func (a *App) Ldap() einterfaces.LdapInterface { - return a.ldap + return a.srv.Ldap } func (a *App) MessageExport() einterfaces.MessageExportInterface { return a.messageExport @@ -491,10 +479,10 @@ func (a *App) Metrics() einterfaces.MetricsInterface { return a.metrics } func (a *App) Notification() einterfaces.NotificationInterface { - return a.notification + return a.srv.Notification } func (a *App) Saml() einterfaces.SamlInterface { - return a.saml + return a.srv.Saml } func (a *App) HTTPService() httpservice.HTTPService { return a.httpService diff --git a/app/options.go b/app/options.go index 5f493db48b..1bfb864477 100644 --- a/app/options.go +++ b/app/options.go @@ -100,7 +100,6 @@ func ServerConnector(s *Server) AppOption { a.log = s.Log a.notificationsLog = s.NotificationsLog - a.accountMigration = s.AccountMigration a.cluster = s.Cluster a.compliance = s.Compliance a.dataRetention = s.DataRetention