From f2db091ab117de456692f59285d50a2509b226c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Er=C3=A8be=20-=20Romain=20Gerard?= Date: Thu, 21 Dec 2023 18:57:24 +0100 Subject: [PATCH] fix: Remove debug print & restore console state after shell (#228) --- pkg/shell.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/shell.go b/pkg/shell.go index 4c2827d4..60ff84f8 100644 --- a/pkg/shell.go +++ b/pkg/shell.go @@ -1,6 +1,7 @@ package pkg import ( + "errors" "github.com/appscode/go-querystring/query" "net/http" "net/url" @@ -37,6 +38,10 @@ func ExecShell(req *ShellRequest) { }() currentConsole := console.Current() + defer func() { + _ = currentConsole.Reset() + }() + if err := currentConsole.SetRaw(); err != nil { log.Fatal("error while setting up console", err) } @@ -62,7 +67,6 @@ func ExecShell(req *ShellRequest) { func createWebsocketConn(req *ShellRequest) (*websocket.Conn, error) { command, err := query.Values(req) - println("", command.Encode(), req.PodName) if err != nil { return nil, err } @@ -92,8 +96,13 @@ func readWebsocketConnection(wsConn *websocket.Conn, currentConsole console.Cons for { _, msg, err := wsConn.ReadMessage() if err != nil { - if e, ok := err.(*websocket.CloseError); ok { - log.Error("connection closed by server: ", e) + var e *websocket.CloseError + if errors.As(err, &e) { + if e.Code == websocket.CloseNormalClosure { + log.Info("** shell terminated bye **") + } else { + log.Error("connection closed by server: ", e) + } return } log.Error("error while reading on websocket:", err)