修复插件并发执行的BUG
This commit is contained in:
parent
507f1f5090
commit
7e30b1f8b9
@ -12,6 +12,7 @@ import (
|
||||
"git.zhangdeman.cn/gateway/core/define"
|
||||
"git.zhangdeman.cn/gateway/core/plugins/abstract"
|
||||
"git.zhangdeman.cn/zhangdeman/trace"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@ -81,12 +82,15 @@ func NewPluginResult(rc *define.RequestContext) *define.PluginResult {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:07 2024/11/13
|
||||
func Dispatch(rc *define.RequestContext, pluginIDList []string) (map[string]abstract.IPlugin, error) {
|
||||
func Dispatch(rc *define.RequestContext, pluginIDList []string) error {
|
||||
l := &sync.RWMutex{}
|
||||
errList := []string{}
|
||||
wg := &sync.WaitGroup{}
|
||||
for _, itemPluginID := range pluginIDList {
|
||||
wg.Add(1)
|
||||
go func(pluginID string) {
|
||||
defer func() {
|
||||
wg.Done()
|
||||
if r := recover(); r != nil {
|
||||
l.Lock()
|
||||
errList = append(errList, r.(error).Error())
|
||||
@ -114,9 +118,14 @@ func Dispatch(rc *define.RequestContext, pluginIDList []string) (map[string]abst
|
||||
l.Unlock()
|
||||
return
|
||||
}
|
||||
rc.SetPluginResult(pluginResult)
|
||||
}(itemPluginID)
|
||||
}
|
||||
return nil, nil
|
||||
wg.Wait()
|
||||
if len(errList) > 0 {
|
||||
return errors.New(strings.Join(errList, "|"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitDefault 初始化注册默认的插件
|
||||
|
Loading…
x
Reference in New Issue
Block a user