MM-19628: Fix race in (*registeredPlugin).State access (#13332)
* MM-19628: Fix race in (*registeredPlugin).State access We used a pointer to an integer in the State variable, and therefore setting a pointer value directly caused a race condition. Since the registeredPlugin is a private struct, changing it to a normal int creates fewer pointers and lets us to fix the race condition by simply setting the integer value and then doing a registeredPlugins.Store. The alternative to keeping the pointer would be to create a copy of each member of a registeredPlugin and do a store again, which I feel is a roundabout way to achieve this. * Address review comments Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
81efef7b5a
Коммит
edddabf95c
@@ -29,7 +29,7 @@ type apiImplCreatorFunc func(*model.Manifest) API
|
||||
// plugin is configured as disabled and has not been activated during this server run.
|
||||
type registeredPlugin struct {
|
||||
BundleInfo *model.BundleInfo
|
||||
State *int
|
||||
State int
|
||||
|
||||
failTimeStamps []time.Time
|
||||
lastError error
|
||||
@@ -114,13 +114,13 @@ func (env *Environment) GetPluginState(id string) int {
|
||||
return model.PluginStateNotRunning
|
||||
}
|
||||
|
||||
return *rp.(*registeredPlugin).State
|
||||
return rp.(*registeredPlugin).State
|
||||
}
|
||||
|
||||
// SetPluginState sets the current state of a plugin (disabled, running, or error)
|
||||
func (env *Environment) SetPluginState(id string, state int) {
|
||||
if rp, ok := env.registeredPlugins.Load(id); ok {
|
||||
*rp.(*registeredPlugin).State = state
|
||||
rp.(*registeredPlugin).State = state
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,5 +441,5 @@ func (env *Environment) RunMultiPluginHook(hookRunnerFunc func(hooks Hooks) bool
|
||||
|
||||
func newRegisteredPlugin(bundle *model.BundleInfo) *registeredPlugin {
|
||||
state := model.PluginStateNotRunning
|
||||
return ®isteredPlugin{failTimeStamps: []time.Time{}, State: &state, BundleInfo: bundle}
|
||||
return ®isteredPlugin{failTimeStamps: []time.Time{}, State: state, BundleInfo: bundle}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user