server: Fix defer function closure escape

Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
Marek Siarkowicz 2023-03-30 13:37:19 +02:00
parent 6637aee804
commit 073c530989

View File

@ -685,17 +685,17 @@ func configureClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err erro
sctx.l = transport.LimitListener(sctx.l, int(fdLimit-reservedInternalFDNum)) sctx.l = transport.LimitListener(sctx.l, int(fdLimit-reservedInternalFDNum))
} }
defer func(addr string) { defer func(sctx *serveCtx) {
if err == nil || sctx.l == nil { if err == nil || sctx.l == nil {
return return
} }
sctx.l.Close() sctx.l.Close()
cfg.logger.Warn( cfg.logger.Warn(
"closing peer listener", "closing peer listener",
zap.String("address", addr), zap.String("address", sctx.addr),
zap.Error(err), zap.Error(err),
) )
}(sctx.addr) }(sctx)
for k := range cfg.UserHandlers { for k := range cfg.UserHandlers {
sctx.userHandlers[k] = cfg.UserHandlers[k] sctx.userHandlers[k] = cfg.UserHandlers[k]
} }