Skip to content

Commit a88f338

Browse files
committed
fix: use separate request context for mirror requests
1 parent 32b80d9 commit a88f338

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

controllers/proxy_controller.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,26 @@ func (_this *proxyController) processRequest(
144144
targetURL *url.URL,
145145
traceID string,
146146
) {
147+
// Create appropriate context based on request type
148+
var reqContext context.Context
149+
if reqType == mirrorRequest {
150+
// For mirror requests, use controller context with timeout.
151+
var cancel context.CancelFunc
152+
reqContext, cancel = context.WithTimeout(_this.ctx, _this.cfg.Proxy.Timeout)
153+
defer cancel()
154+
} else {
155+
// For proxy requests, use the gin context
156+
reqContext = c.Request.Context()
157+
}
158+
147159
// Instead of cloning, create a new request.
148160
targetPath := c.Request.URL.Path
149161
if c.Request.URL.RawQuery != "" {
150162
targetPath += "?" + c.Request.URL.RawQuery
151163
}
152164

153165
req, err := http.NewRequestWithContext(
154-
c.Request.Context(),
166+
reqContext,
155167
c.Request.Method,
156168
targetURL.String()+targetPath,
157169
bytes.NewBuffer(bodyBytes),

0 commit comments

Comments
 (0)