File tree 2 files changed +37
-3
lines changed
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) {
6126
6126
}
6127
6127
}
6128
6128
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
+
6129
6162
// Issue 30710: ensure that as per the spec, a server responds
6130
6163
// with 501 Not Implemented for unsupported transfer-encodings.
6131
6164
func 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 {
2920
2920
}
2921
2921
return err
2922
2922
}
2923
+ connCtx := ctx
2923
2924
if cc := srv .ConnContext ; cc != nil {
2924
- ctx = cc (ctx , rw )
2925
- if ctx == nil {
2925
+ connCtx = cc (connCtx , rw )
2926
+ if connCtx == nil {
2926
2927
panic ("ConnContext returned nil" )
2927
2928
}
2928
2929
}
2929
2930
tempDelay = 0
2930
2931
c := srv .newConn (rw )
2931
2932
c .setState (c .rwc , StateNew ) // before Serve can return
2932
- go c .serve (ctx )
2933
+ go c .serve (connCtx )
2933
2934
}
2934
2935
}
2935
2936
You can’t perform that action at this time.
0 commit comments