embed: deep copy user handlers

Shallow copy of user handlers leads to a nil map assignment when
enabling pprof. Since the map is being modified, it should probably
be deep copied into the server context, which fixes the crash.
This commit is contained in:
Anthony Romano 2016-12-14 10:12:40 -08:00
parent 1e60f88786
commit cc931a2319
2 changed files with 4 additions and 2 deletions

View File

@ -286,7 +286,9 @@ func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
plog.Info("stopping listening for client requests on ", u.Host)
}
}()
sctx.userHandlers = cfg.UserHandlers
for k := range cfg.UserHandlers {
sctx.userHandlers[k] = cfg.UserHandlers[k]
}
if cfg.EnablePprof {
sctx.registerPprof()
}

View File

@ -51,7 +51,7 @@ type serveCtx struct {
func newServeCtx() *serveCtx {
ctx, cancel := context.WithCancel(context.Background())
return &serveCtx{ctx: ctx, cancel: cancel}
return &serveCtx{ctx: ctx, cancel: cancel, userHandlers: make(map[string]http.Handler)}
}
// serve accepts incoming connections on the listener l,