Skip to content

Commit

Permalink
fix: writing clusterfail to hijacked connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco98 committed Aug 3, 2024
1 parent d8b3b79 commit 185a10a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/proxy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ func (p *Proxy) proxyHandler() func(w http.ResponseWriter, r *http.Request) {
} else {
log.WithError(err).Error("failed to proxy request")
}
if err := p.getClusterFailSite(w); err != nil {
log.WithError(err).Error("error writing error to response")
// prevent writing to hijacked connection
if !errors.Is(err, errProxyWs) {
if err := p.getClusterFailSite(w); err != nil {
log.WithError(err).Error("error writing error to response")
}
}
}
}
Expand Down Expand Up @@ -198,7 +201,7 @@ func (p *Proxy) proxyWebsocket(cluster string, w http.ResponseWriter, r *http.Re
case err = <-berr:
}
if e, ok := err.(*websocket.CloseError); !ok || e.Code == websocket.CloseAbnormalClosure {
return fmt.Errorf("error while proxing ws: %w", err)
return errors.Join(errProxyWs, err)
}
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (
localHTTPDir = "/pveportal/"
)

var errProxyWs = errors.New("error while proxing ws")

func Run(www embed.FS) error {
cpath := flag.String("c", "pveportal.yaml", "config path")
loglevel := flag.String("l", "INFO", "loglevel")
Expand Down

0 comments on commit 185a10a

Please sign in to comment.