File tree Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -6126,6 +6126,39 @@ func TestServerContextsHTTP2(t *testing.T) {
61266126 }
61276127}
61286128
6129+ // Issue 35750: check ConnContext not modifying context for other connections
6130+ func TestConnContextNotModifyingAllContexts (t * testing.T ) {
6131+ setParallel (t )
6132+ defer afterTest (t )
6133+ type connKey struct {}
6134+ ts := httptest .NewUnstartedServer (HandlerFunc (func (rw ResponseWriter , r * Request ) {
6135+ rw .Header ().Set ("Connection" , "close" )
6136+ }))
6137+ ts .Config .ConnContext = func (ctx context.Context , c net.Conn ) context.Context {
6138+ if got := ctx .Value (connKey {}); got != nil {
6139+ t .Errorf ("in ConnContext, unexpected context key = %#v" , got )
6140+ }
6141+ return context .WithValue (ctx , connKey {}, "conn" )
6142+ }
6143+ ts .Start ()
6144+ defer ts .Close ()
6145+
6146+ var res * Response
6147+ var err error
6148+
6149+ res , err = ts .Client ().Get (ts .URL )
6150+ if err != nil {
6151+ t .Fatal (err )
6152+ }
6153+ res .Body .Close ()
6154+
6155+ res , err = ts .Client ().Get (ts .URL )
6156+ if err != nil {
6157+ t .Fatal (err )
6158+ }
6159+ res .Body .Close ()
6160+ }
6161+
61296162// Issue 30710: ensure that as per the spec, a server responds
61306163// with 501 Not Implemented for unsupported transfer-encodings.
61316164func TestUnsupportedTransferEncodingsReturn501 (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -2920,16 +2920,17 @@ func (srv *Server) Serve(l net.Listener) error {
29202920 }
29212921 return err
29222922 }
2923+ connCtx := ctx
29232924 if cc := srv .ConnContext ; cc != nil {
2924- ctx = cc (ctx , rw )
2925- if ctx == nil {
2925+ connCtx = cc (connCtx , rw )
2926+ if connCtx == nil {
29262927 panic ("ConnContext returned nil" )
29272928 }
29282929 }
29292930 tempDelay = 0
29302931 c := srv .newConn (rw )
29312932 c .setState (c .rwc , StateNew ) // before Serve can return
2932- go c .serve (ctx )
2933+ go c .serve (connCtx )
29332934 }
29342935}
29352936
You can’t perform that action at this time.
0 commit comments