21285: Propagate HTTP status code in tunnel setup error.
authorTom Clegg <tom@curii.com>
Mon, 1 Jan 2024 21:46:50 +0000 (16:46 -0500)
committerTom Clegg <tom@curii.com>
Mon, 1 Jan 2024 21:46:50 +0000 (16:46 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

lib/controller/rpc/conn.go
lib/crunchrun/container_gateway.go

index a8ecc57bbaa4512e0a0becc81e25f61f2b60316f..9f518d9c7a91027a0ddc6552a341455b14b5f256 100644 (file)
@@ -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}
index 30f8957a2de7ccc33218302a1d72cbea09a3ecb7..5b68e2c50ebaa88168c31039706f6aa5a3b3c38f 100644 (file)
@@ -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 {