Skip to content

Commit

Permalink
fix a bug of reusing range variable
Browse files Browse the repository at this point in the history
It works stably and no more bugs found.
  • Loading branch information
AZ-X committed May 13, 2021
1 parent 3f32628 commit 6e76dce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion repique/features/dns/nodes/dnscrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (n *dnscryptnode) unmarshal(ss *struct{c uint8; v string}) *time.Time {
n.V2_Services = append(n.V2_Services, s)
}
n.bs2epring()
to := time.Unix(int64(s.DtTo), 0).UTC()
to := time.Unix(int64(s.DtTo), 0)
return &to
}

Expand Down
11 changes: 5 additions & 6 deletions repique/features/dns/nodes/node_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ func (mgr *NodesMgr) associate() {
svrs[idx] = servers
}
}
for idx, lc := range *mgr.L2NMapping {
for i, lc := range *mgr.L2NMapping {
idx := i //capture range variable
if lc == nil && idx != 0 {
continue
}
Expand Down Expand Up @@ -670,11 +671,7 @@ func (mgr *NodesMgr) associate() {
servers := make([]_DNSService, 0)
if idx != 0 {
for _, name := range lc.ServerList.Servers {
if node := mgr.nodes[*name]; node.status&(
status_unusable|
status_outdated|
status_broken |
status_bootstrapping) ==0 {
if node := mgr.nodes[*name]; node.applicable() {
servers = append(servers, node._DNSService)
}
}
Expand Down Expand Up @@ -706,6 +703,7 @@ func (mgr *NodesMgr) pick(s *channels.Session) _DNSService {
}
return nil
}

var candidates []_DNSService
if mgr.q2nodesFunc != nil {
if f := (*mgr.q2nodesFunc)[s.Listener]; f != nil {
Expand All @@ -714,6 +712,7 @@ func (mgr *NodesMgr) pick(s *channels.Session) _DNSService {
} else {
candidates = (*mgr.groups)[0][0]
}

cc := len(candidates)
if cc == 1 {
return candidates[0]
Expand Down

0 comments on commit 6e76dce

Please sign in to comment.