Commit 1d95943f authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Improve WAF service mode update with concurrent listener processing

- Add synchronization mechanism using sync.WaitGroup
- Implement concurrent goroutine updates for WAF service listeners
- Ensure all listener updates complete before returning
- Create local listener variable to prevent goroutine closure issues
parent 0fabf210
......@@ -12,6 +12,7 @@ import (
"os"
"strconv"
"strings"
"sync"
"github.com/rs/zerolog/log"
"gitlab.com/tensorsecurity-rd/waf-console/internal/model"
......@@ -289,9 +290,12 @@ func (s *wafService) UpdateMode(ctx context.Context, req *UpdateModeReq) (*WafSe
if err != nil {
return nil, fmt.Errorf("failed to get listener list: %v", err)
}
var wg sync.WaitGroup
for _, listener := range listenerList.Items {
wg.Add(1)
listener := listener // Create new variable for goroutine
go func() {
defer wg.Done()
log.Info().Msgf("update WAF service mode: %v", listener.Name)
_, err := client.WafV1alpha1().Services(req.Namespace).Update(ctx, &listener, metav1.UpdateOptions{})
if err != nil {
......@@ -299,6 +303,7 @@ func (s *wafService) UpdateMode(ctx context.Context, req *UpdateModeReq) (*WafSe
}
}()
}
wg.Wait()
return &WafService{
GatewayName: req.GatewayName,
Mode: string(req.Mode),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment