MM-21019 - Fix race in (*Environment).SetPluginState() (#13610)
* MM-21019 - Fix race in (*Environment).SetPluginState() - We change from passing pointers to registeredPlugin to passing the struct by value. - We also add a mutex to the supervisor struct to protect from racy data access. * move the immutability comment to the godoc of the Active method * Changing mut to lock Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3892db4613
Коммит
21034c3513
@@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
plugin "github.com/hashicorp/go-plugin"
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
)
|
||||
|
||||
type supervisor struct {
|
||||
lock sync.RWMutex
|
||||
client *plugin.Client
|
||||
hooks Hooks
|
||||
implemented [TotalHooksId]bool
|
||||
@@ -99,17 +101,22 @@ func newSupervisor(pluginInfo *model.BundleInfo, parentLogger *mlog.Logger, apiI
|
||||
}
|
||||
|
||||
func (sup *supervisor) Shutdown() {
|
||||
sup.lock.RLock()
|
||||
defer sup.lock.RUnlock()
|
||||
if sup.client != nil {
|
||||
sup.client.Kill()
|
||||
}
|
||||
}
|
||||
|
||||
func (sup *supervisor) Hooks() Hooks {
|
||||
sup.lock.RLock()
|
||||
defer sup.lock.RUnlock()
|
||||
return sup.hooks
|
||||
}
|
||||
|
||||
// PerformHealthCheck checks the plugin through an an RPC ping.
|
||||
func (sup *supervisor) PerformHealthCheck() error {
|
||||
// No need for a lock here because Ping is read-locked.
|
||||
if pingErr := sup.Ping(); pingErr != nil {
|
||||
for pingFails := 1; pingFails < HEALTH_CHECK_PING_FAIL_LIMIT; pingFails++ {
|
||||
pingErr = sup.Ping()
|
||||
@@ -128,8 +135,9 @@ func (sup *supervisor) PerformHealthCheck() error {
|
||||
|
||||
// Ping checks that the RPC connection with the plugin is alive and healthy.
|
||||
func (sup *supervisor) Ping() error {
|
||||
sup.lock.RLock()
|
||||
defer sup.lock.RUnlock()
|
||||
client, err := sup.client.Client()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -138,5 +146,7 @@ func (sup *supervisor) Ping() error {
|
||||
}
|
||||
|
||||
func (sup *supervisor) Implements(hookId int) bool {
|
||||
sup.lock.RLock()
|
||||
defer sup.lock.RUnlock()
|
||||
return sup.implemented[hookId]
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user