From 6b1cc1088eba17ff02d7ba1cea42197217e7388f Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Sat, 7 Oct 2023 14:32:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E9=98=B2=E7=81=AB?= =?UTF-8?q?=E5=A2=99=20ip=20=E8=A7=84=E5=88=99=E6=89=B9=E9=87=8F=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98=20(#2435?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #2421 #2430 --- backend/app/service/firewall.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/app/service/firewall.go b/backend/app/service/firewall.go index e271e5807..777cbc0d3 100644 --- a/backend/app/service/firewall.go +++ b/backend/app/service/firewall.go @@ -233,6 +233,7 @@ func (u *FirewallService) OperatePortRule(req dto.PortRuleOperate, reload bool) }(req) } } + wg.Wait() return nil } if req.Protocol == "tcp/udp" { @@ -314,20 +315,20 @@ func (u *FirewallService) OperateAddressRule(req dto.AddrRuleOperate, reload boo var wg sync.WaitGroup addressList := strings.Split(req.Address, ",") - for _, addr := range addressList { - if len(addr) == 0 { + for i := 0; i < len(addressList); i++ { + if len(addressList[i]) == 0 { continue } - fireInfo.Address = addr wg.Add(1) - go func(req dto.AddrRuleOperate) { + go func(addr string) { defer wg.Done() + fireInfo.Address = addr if err := client.RichRules(fireInfo, req.Operation); err != nil { - global.LOG.Errorf("%s address %s failed (strategy: %s), err: %v", req.Operation, req.Address, req.Strategy, err) + global.LOG.Errorf("%s address %s failed (strategy: %s), err: %v", req.Operation, addr, req.Strategy, err) } - req.Address = fireInfo.Address + req.Address = addr _ = u.addAddressRecord(req) - }(req) + }(addressList[i]) } wg.Wait() if reload { @@ -397,6 +398,7 @@ func (u *FirewallService) BatchOperateRule(req dto.BatchRuleOperate) error { _ = u.OperateAddressRule(item, false) }(itemRule) } + wgBatch.Wait() return client.Reload() }