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 @@ -6121,6 +6121,39 @@ func TestServerContextsHTTP2(t *testing.T) {
6121
6121
}
6122
6122
}
6123
6123
6124
+ // Issue 35750: check ConnContext not modifying context for other connections
6125
+ func TestConnContextNotModifyingAllContexts (t * testing.T ) {
6126
+ setParallel (t )
6127
+ defer afterTest (t )
6128
+ type connKey struct {}
6129
+ ts := httptest .NewUnstartedServer (HandlerFunc (func (rw ResponseWriter , r * Request ) {
6130
+ rw .Header ().Set ("Connection" , "close" )
6131
+ }))
6132
+ ts .Config .ConnContext = func (ctx context.Context , c net.Conn ) context.Context {
6133
+ if got := ctx .Value (connKey {}); got != nil {
6134
+ t .Errorf ("in ConnContext, unexpected context key = %#v" , got )
6135
+ }
6136
+ return context .WithValue (ctx , connKey {}, "conn" )
6137
+ }
6138
+ ts .Start ()
6139
+ defer ts .Close ()
6140
+
6141
+ var res * Response
6142
+ var err error
6143
+
6144
+ res , err = ts .Client ().Get (ts .URL )
6145
+ if err != nil {
6146
+ t .Fatal (err )
6147
+ }
6148
+ res .Body .Close ()
6149
+
6150
+ res , err = ts .Client ().Get (ts .URL )
6151
+ if err != nil {
6152
+ t .Fatal (err )
6153
+ }
6154
+ res .Body .Close ()
6155
+ }
6156
+
6124
6157
// Issue 30710: ensure that as per the spec, a server responds
6125
6158
// with 501 Not Implemented for unsupported transfer-encodings.
6126
6159
func TestUnsupportedTransferEncodingsReturn501 (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -2915,16 +2915,17 @@ func (srv *Server) Serve(l net.Listener) error {
2915
2915
}
2916
2916
return e
2917
2917
}
2918
+ connCtx := ctx
2918
2919
if cc := srv .ConnContext ; cc != nil {
2919
- ctx = cc (ctx , rw )
2920
- if ctx == nil {
2920
+ connCtx = cc (connCtx , rw )
2921
+ if connCtx == nil {
2921
2922
panic ("ConnContext returned nil" )
2922
2923
}
2923
2924
}
2924
2925
tempDelay = 0
2925
2926
c := srv .newConn (rw )
2926
2927
c .setState (c .rwc , StateNew ) // before Serve can return
2927
- go c .serve (ctx )
2928
+ go c .serve (connCtx )
2928
2929
}
2929
2930
}
2930
2931
You can’t perform that action at this time.
0 commit comments