Skip to content

Commit

Permalink
fix: Remove debug print & restore console state after shell (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
erebe authored Dec 21, 2023
1 parent cc95a0e commit f2db091
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/shell.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pkg

import (
"errors"
"github.com/appscode/go-querystring/query"
"net/http"
"net/url"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f2db091

Please sign in to comment.