MM-31370: Fix racy TestClusterShutdownRace (#16562)

* MM-31370: Fix racy TestClusterShutdownRace

This race wasn't specific to this test, but somehow got triggered by it.
This was a critical race because the PluginsLock is widely used
throughout the codebase to gate access to the PluginsEnvironment.

However, a config listener can often run in its own goroutine leading to
a wide variety of races.

https://mattermost.atlassian.net/browse/MM-31370

```release-note
NONE
```

* incorporate review comments

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2021-01-07 15:38:37 +05:30
коммит произвёл GitHub
родитель 091659c8ad
Коммит 092c07a18c

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

@@ -500,7 +500,9 @@ func NewServer(options ...Option) (*Server, error) {
pluginsEnvironment.InitPluginHealthCheckJob(*s.Config().PluginSettings.Enable && *s.Config().PluginSettings.EnableHealthCheck)
}
s.AddConfigListener(func(_, c *model.Config) {
s.PluginsLock.RLock()
pluginsEnvironment := s.PluginsEnvironment
s.PluginsLock.RUnlock()
if pluginsEnvironment != nil {
pluginsEnvironment.InitPluginHealthCheckJob(*s.Config().PluginSettings.Enable && *c.PluginSettings.EnableHealthCheck)
}