mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
fix: pass argument url in defer to avoid loopclosure
Because of the well-known range loop closure issue, the value of u may have changed by the time the anonymous function mentioned in the defer is run. To address this, the simplest fix is to pass the url used in the loop as an argument to the function run in defer.
This commit is contained in:
parent
b5cefb5b3d
commit
3f6e0ec94b
@ -589,7 +589,7 @@ func configureClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err erro
|
||||
}
|
||||
}
|
||||
|
||||
defer func() {
|
||||
defer func(u url.URL) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
@ -599,7 +599,7 @@ func configureClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err erro
|
||||
zap.String("address", u.Host),
|
||||
zap.Error(err),
|
||||
)
|
||||
}()
|
||||
}(u)
|
||||
for k := range cfg.UserHandlers {
|
||||
sctx.userHandlers[k] = cfg.UserHandlers[k]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user