Skip to content

Commit dcb9290

Browse files
blink-so[bot]f0ssel
andcommitted
Add detailed error logging and context timeout for HTTP requests
- Add explicit context timeout for forward HTTP requests - Log detailed error information including error type - Helps identify why HTTP forwarding fails immediately - Should reveal the root cause of connection failures Co-authored-by: f0ssel <[email protected]>
1 parent d6845b9 commit dcb9290

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

proxy/proxy.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,13 @@ func (p *Server) forwardHTTPRequest(w http.ResponseWriter, r *http.Request) {
222222
p.logger.Debug("About to make HTTP request", "target", targetURL.String())
223223

224224
// Make the request
225+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
226+
defer cancel()
227+
req = req.WithContext(ctx)
228+
225229
resp, err := client.Do(req)
226230
if err != nil {
227-
p.logger.Error("Failed to make forward request", "error", err)
231+
p.logger.Error("Failed to make forward request", "error", err, "target", targetURL.String(), "error_type", fmt.Sprintf("%T", err))
228232
http.Error(w, fmt.Sprintf("Failed to make request: %v", err), http.StatusBadGateway)
229233
return
230234
}

0 commit comments

Comments
 (0)