Skip to content

Commit

Permalink
fix: Remove debug print & restore console state after shell
Browse files Browse the repository at this point in the history
  • Loading branch information
erebe committed Dec 21, 2023
1 parent cc95a0e commit aeadd51
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 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,8 @@ func ExecShell(req *ShellRequest) {
}()

currentConsole := console.Current()
defer currentConsole.Reset()

Check failure on line 41 in pkg/shell.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `currentConsole.Reset` is not checked (errcheck)

if err := currentConsole.SetRaw(); err != nil {
log.Fatal("error while setting up console", err)
}
Expand All @@ -62,7 +65,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 +94,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 aeadd51

Please sign in to comment.