Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 00:30 UTC
reverseproxy: Connection termination cleanup (#5663)
mmm444 committed
Aug 1, 2023 at 16:01 UTC
da23501457e90024814fe0149aaa57dd4384227a
1 file changed
+19
-6
modules/caddyhttp/reverseproxy/reverseproxy.go
+19
-6
@@ -769,7 +769,7 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, origRe
769
// regardless, and we should expect client disconnection in low-latency streaming
770
// scenarios (see issue #4922)
771
if h.FlushInterval == -1 {
772
- req = req.WithContext(ignoreClientGoneContext{req.Context(), h.ctx.Done()})
772
+ req = req.WithContext(ignoreClientGoneContext{req.Context()})
773
}
774
775
// do the round-trip; emit debug log with values we know are
@@ -1398,15 +1398,28 @@ type handleResponseContext struct {
1398
// ignoreClientGoneContext is a special context.Context type
1399
// intended for use when doing a RoundTrip where you don't
1400
// want a client disconnection to cancel the request during
1401
-// the roundtrip. Set its done field to a Done() channel
1402
-// of a context that doesn't get canceled when the client
1403
-// disconnects, such as caddy.Context.Done() instead.
1401
+// the roundtrip.
1402
+// This context clears cancellation, error, and deadline methods,
1403
+// but still allows values to pass through from its embedded
1404
+// context.
1405
+//
1406
+// TODO: This can be replaced with context.WithoutCancel once
1407
+// the minimum required version of Go is 1.21.
1408
type ignoreClientGoneContext struct {
1409
context.Context
1406
- done <-chan struct{}
1410
}
1411
1409
-func (c ignoreClientGoneContext) Done() <-chan struct{} { return c.done }
1412
+func (c ignoreClientGoneContext) Deadline() (deadline time.Time, ok bool) {
1413
+ return
1414
+}
1415
+
1416
+func (c ignoreClientGoneContext) Done() <-chan struct{} {
1417
+ return nil
1418
+}
1419
+
1420
+func (c ignoreClientGoneContext) Err() error {
1421
+ return nil
1422
+}
1423
1424
// proxyHandleResponseContextCtxKey is the context key for the active proxy handler
1425
// so that handle_response routes can inherit some config options