net/http: fix Server.ConnContext modifying context for all new connections

Fixes #35750
This commit is contained in:
Roman Kollár 2019-11-21 18:05:35 +01:00
parent 8bbfc51d9a
commit 827fb3f45a
1 changed files with 4 additions and 3 deletions

View File

@ -2920,16 +2920,17 @@ func (srv *Server) Serve(l net.Listener) error {
}
return err
}
connCtx := ctx
if cc := srv.ConnContext; cc != nil {
ctx = cc(ctx, rw)
if ctx == nil {
connCtx = cc(connCtx, rw)
if connCtx == nil {
panic("ConnContext returned nil")
}
}
tempDelay = 0
c := srv.newConn(rw)
c.setState(c.rwc, StateNew) // before Serve can return
go c.serve(ctx)
go c.serve(connCtx)
}
}