From a5af8485c9658e13c6ef40981138731b0db35a68 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Mon, 1 Jan 2024 16:46:50 -0500 Subject: [PATCH] 21285: Propagate HTTP status code in tunnel setup error. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- lib/controller/rpc/conn.go | 4 ++-- lib/crunchrun/container_gateway.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/controller/rpc/conn.go b/lib/controller/rpc/conn.go index a8ecc57bba..9f518d9c7a 100644 --- a/lib/controller/rpc/conn.go +++ b/lib/controller/rpc/conn.go @@ -482,11 +482,11 @@ func (conn *Conn) socket(ctx context.Context, u *url.URL, upgradeHeader string, } else { message = fmt.Sprintf("%q", body) } - return connresp, fmt.Errorf("server did not provide a tunnel: %s: %s", resp.Status, message) + return connresp, httpserver.ErrorWithStatus(fmt.Errorf("server did not provide a tunnel: %s: %s", resp.Status, message), resp.StatusCode) } if strings.ToLower(resp.Header.Get("Upgrade")) != upgradeHeader || strings.ToLower(resp.Header.Get("Connection")) != "upgrade" { - return connresp, fmt.Errorf("bad response from server: Upgrade %q Connection %q", resp.Header.Get("Upgrade"), resp.Header.Get("Connection")) + return connresp, httpserver.ErrorWithStatus(fmt.Errorf("bad response from server: Upgrade %q Connection %q", resp.Header.Get("Upgrade"), resp.Header.Get("Connection")), http.StatusBadGateway) } connresp.Conn = netconn connresp.Bufrw = &bufio.ReadWriter{Reader: bufr, Writer: bufw} diff --git a/lib/crunchrun/container_gateway.go b/lib/crunchrun/container_gateway.go index 30f8957a2d..5b68e2c50e 100644 --- a/lib/crunchrun/container_gateway.go +++ b/lib/crunchrun/container_gateway.go @@ -220,7 +220,7 @@ func (gw *Gateway) runTunnel(addr string) error { AuthSecret: gw.AuthSecret, }) if err != nil { - return fmt.Errorf("error creating gateway tunnel: %s", err) + return fmt.Errorf("error creating gateway tunnel: %w", err) } mux, err := yamux.Client(tun.Conn, nil) if err != nil { -- 2.30.2