From 039247d9df3d665f636cfdd9873d02a5be20890a Mon Sep 17 00:00:00 2001 From: whxaxes Date: Thu, 4 Jan 2024 15:21:37 +0800 Subject: [PATCH 1/2] fix: should break the loop --- ws_reverse_proxy.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ws_reverse_proxy.go b/ws_reverse_proxy.go index 90aa925..22faffe 100644 --- a/ws_reverse_proxy.go +++ b/ws_reverse_proxy.go @@ -137,9 +137,12 @@ func (w *WSReverseProxy) ServeHTTP(ctx context.Context, c *app.RequestContext) { var ce *websocket.CloseError var hzce *hzws.CloseError - if !errors.As(err, &ce) || !errors.As(err, &hzce) { + if !errors.As(err, &ce) && !errors.As(err, &hzce) { hlog.CtxErrorf(ctx, errMsg, err) + continue } + + break } }); err != nil { hlog.CtxErrorf(ctx, "can not upgrade to websocket: %v", err) From 5f1febda63f443a3fabbc8293a8ed96ab9bf8b60 Mon Sep 17 00:00:00 2001 From: kinggo Date: Thu, 4 Jan 2024 15:49:41 +0800 Subject: [PATCH 2/2] chore: modify unit test --- ws_reverse_proxy_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ws_reverse_proxy_test.go b/ws_reverse_proxy_test.go index b372ea7..83fd506 100644 --- a/ws_reverse_proxy_test.go +++ b/ws_reverse_proxy_test.go @@ -55,6 +55,7 @@ func TestProxy(t *testing.T) { // proxy server ps := server.Default(server.WithHostPorts(":7777")) + ps.NoHijackConnPool = true ps.GET("/proxy", proxy.ServeHTTP) go ps.Spin() @@ -63,6 +64,7 @@ func TestProxy(t *testing.T) { go func() { // backend server bs := server.Default() + bs.NoHijackConnPool = true bs.GET("/", func(ctx context.Context, c *app.RequestContext) { // Don't upgrade if original host header isn't preserved host := string(c.Host())