1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 16:29:17 +08:00

fix: 解决防火墙 ip 规则批量操作失败的问题 (#2435)

Refs #2421 #2430
This commit is contained in:
ssongliu 2023-10-07 14:32:43 +08:00 committed by GitHub
parent bca9777a43
commit 6b1cc1088e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -233,6 +233,7 @@ func (u *FirewallService) OperatePortRule(req dto.PortRuleOperate, reload bool)
}(req) }(req)
} }
} }
wg.Wait()
return nil return nil
} }
if req.Protocol == "tcp/udp" { if req.Protocol == "tcp/udp" {
@ -314,20 +315,20 @@ func (u *FirewallService) OperateAddressRule(req dto.AddrRuleOperate, reload boo
var wg sync.WaitGroup var wg sync.WaitGroup
addressList := strings.Split(req.Address, ",") addressList := strings.Split(req.Address, ",")
for _, addr := range addressList { for i := 0; i < len(addressList); i++ {
if len(addr) == 0 { if len(addressList[i]) == 0 {
continue continue
} }
fireInfo.Address = addr
wg.Add(1) wg.Add(1)
go func(req dto.AddrRuleOperate) { go func(addr string) {
defer wg.Done() defer wg.Done()
fireInfo.Address = addr
if err := client.RichRules(fireInfo, req.Operation); err != nil { 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) _ = u.addAddressRecord(req)
}(req) }(addressList[i])
} }
wg.Wait() wg.Wait()
if reload { if reload {
@ -397,6 +398,7 @@ func (u *FirewallService) BatchOperateRule(req dto.BatchRuleOperate) error {
_ = u.OperateAddressRule(item, false) _ = u.OperateAddressRule(item, false)
}(itemRule) }(itemRule)
} }
wgBatch.Wait()
return client.Reload() return client.Reload()
} }