Skip to content

Commit

Permalink
fix(proxy): handle client disconnect from round tripper using proxy e…
Browse files Browse the repository at this point in the history
…rror
  • Loading branch information
unkn0wn-root committed Jan 4, 2025
1 parent 2067518 commit f636eec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 7 additions & 7 deletions internal/pool/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ const (
RetryAfterSec = 5
)

// ErrorResponse represents the structure of error responses sent to clients
type ErrorResponse struct {
Status string `json:"status"`
Message string `json:"message"`
RetryAfter int `json:"retry_after,omitempty"`
}

// ProxyErrorCode represents specific error conditions in the proxy
type ProxyErrorCode int

Expand Down Expand Up @@ -189,13 +196,6 @@ func NewProxyError(op string, err error) *ProxyError {
return pe
}

// ErrorResponse represents the structure of error responses sent to clients
type ErrorResponse struct {
Status string `json:"status"`
Message string `json:"message"`
RetryAfter int `json:"retry_after,omitempty"`
}

// WriteErrorResponse writes a structured error response to the client
func WriteErrorResponse(w http.ResponseWriter, err error) {
var pe *ProxyError
Expand Down
10 changes: 7 additions & 3 deletions internal/pool/proxy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pool

import (
"context"
"crypto/tls"
"errors"
"fmt"
Expand Down Expand Up @@ -242,10 +241,15 @@ func (p *URLRewriteProxy) errorHandler(w http.ResponseWriter, r *http.Request, e
// so as for Go 1.23 this is still an issue and we have to live with it
// We don't want to overflow logs with this error as this can happen quite often
// so we just ignore it for now until Go team provide a better solution
if errors.Is(err, context.Canceled) {
return
var proxyErr *ProxyError
if errors.As(err, &proxyErr) {
if proxyErr.Code == ErrCodeClientDisconnect {
return
}
}

// log every error even if error could be non-proxy
// WriteErrorResponse will handle all non-proxy errors but it should not happen (just in case)
p.logger.Error("Proxy error",
zap.Error(err),
zap.String("method", r.Method),
Expand Down

0 comments on commit f636eec

Please sign in to comment.