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 <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2020-08-04 09:16:20 +05:30
коммит произвёл GitHub
родитель d22dd262ee
Коммит 339c5bae76
2 изменённых файлов: 10 добавлений и 23 удалений

Просмотреть файл

@@ -38,16 +38,12 @@ type App struct {
userAgent string userAgent string
acceptLanguage string acceptLanguage string
accountMigration einterfaces.AccountMigrationInterface cluster einterfaces.ClusterInterface
cluster einterfaces.ClusterInterface compliance einterfaces.ComplianceInterface
compliance einterfaces.ComplianceInterface dataRetention einterfaces.DataRetentionInterface
dataRetention einterfaces.DataRetentionInterface searchEngine *searchengine.Broker
searchEngine *searchengine.Broker messageExport einterfaces.MessageExportInterface
ldap einterfaces.LdapInterface metrics einterfaces.MetricsInterface
messageExport einterfaces.MessageExportInterface
metrics einterfaces.MetricsInterface
notification einterfaces.NotificationInterface
saml einterfaces.SamlInterface
httpService httpservice.HTTPService httpService httpservice.HTTPService
imageProxy *imageproxy.ImageProxy imageProxy *imageproxy.ImageProxy
@@ -69,10 +65,6 @@ func New(options ...AppOption) *App {
func (a *App) InitServer() { func (a *App) InitServer() {
a.srv.AppInitializedOnce.Do(func() { a.srv.AppInitializedOnce.Do(func() {
a.initEnterprise() 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) { a.AddConfigListener(func(oldConfig *model.Config, newConfig *model.Config) {
if *oldConfig.GuestAccountsSettings.Enable && !*newConfig.GuestAccountsSettings.Enable { if *oldConfig.GuestAccountsSettings.Enable && !*newConfig.GuestAccountsSettings.Enable {
@@ -116,10 +108,6 @@ func (a *App) InitServer() {
} }
a.srv.RunJobs() 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() { func (a *App) initJobs() {
@@ -467,7 +455,7 @@ func (a *App) AcceptLanguage() string {
return a.acceptLanguage return a.acceptLanguage
} }
func (a *App) AccountMigration() einterfaces.AccountMigrationInterface { func (a *App) AccountMigration() einterfaces.AccountMigrationInterface {
return a.accountMigration return a.srv.AccountMigration
} }
func (a *App) Cluster() einterfaces.ClusterInterface { func (a *App) Cluster() einterfaces.ClusterInterface {
return a.cluster return a.cluster
@@ -482,7 +470,7 @@ func (a *App) SearchEngine() *searchengine.Broker {
return a.searchEngine return a.searchEngine
} }
func (a *App) Ldap() einterfaces.LdapInterface { func (a *App) Ldap() einterfaces.LdapInterface {
return a.ldap return a.srv.Ldap
} }
func (a *App) MessageExport() einterfaces.MessageExportInterface { func (a *App) MessageExport() einterfaces.MessageExportInterface {
return a.messageExport return a.messageExport
@@ -491,10 +479,10 @@ func (a *App) Metrics() einterfaces.MetricsInterface {
return a.metrics return a.metrics
} }
func (a *App) Notification() einterfaces.NotificationInterface { func (a *App) Notification() einterfaces.NotificationInterface {
return a.notification return a.srv.Notification
} }
func (a *App) Saml() einterfaces.SamlInterface { func (a *App) Saml() einterfaces.SamlInterface {
return a.saml return a.srv.Saml
} }
func (a *App) HTTPService() httpservice.HTTPService { func (a *App) HTTPService() httpservice.HTTPService {
return a.httpService return a.httpService

Просмотреть файл

@@ -100,7 +100,6 @@ func ServerConnector(s *Server) AppOption {
a.log = s.Log a.log = s.Log
a.notificationsLog = s.NotificationsLog a.notificationsLog = s.NotificationsLog
a.accountMigration = s.AccountMigration
a.cluster = s.Cluster a.cluster = s.Cluster
a.compliance = s.Compliance a.compliance = s.Compliance
a.dataRetention = s.DataRetention a.dataRetention = s.DataRetention