Skip to content

Commit 070054e

Browse files
Change cap of the err channel.
1 parent a86c6e7 commit 070054e

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

gotty/server/handlers.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8-
"github.com/patrickmn/go-cache"
98
"github.com/KubeOperator/webkubectl/gotty/pkg/randomstring"
9+
"github.com/patrickmn/go-cache"
1010
"io/ioutil"
1111
"log"
1212
"net/http"
@@ -49,8 +49,8 @@ func (server *Server) generateHandleWS(ctx context.Context, cancel context.Cance
4949
defer func() {
5050
num := counter.done()
5151
log.Printf(
52-
"Connection closed by %s: %s, connections: %d/%d",
53-
closeReason, r.RemoteAddr, num, server.options.MaxConnection,
52+
"Connection closed: %s, reason: %s, connections: %d/%d",
53+
r.RemoteAddr, closeReason, num, server.options.MaxConnection,
5454
)
5555

5656
if server.options.Once {
@@ -89,7 +89,9 @@ func (server *Server) generateHandleWS(ctx context.Context, cancel context.Cance
8989
case webtty.ErrSlaveClosed:
9090
closeReason = server.factory.Name()
9191
case webtty.ErrMasterClosed:
92-
closeReason = "client"
92+
closeReason = "client close"
93+
case webtty.ErrConnectionLostPing:
94+
closeReason = webtty.ErrConnectionLostPing.Error()
9395
default:
9496
closeReason = fmt.Sprintf("an error: %s", err)
9597
}

gotty/webtty/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ var (
1010

1111
// ErrSlaveClosed is returned when the slave connection is closed.
1212
ErrMasterClosed = errors.New("master closed")
13+
14+
// ErrConnectionLostPing is returned if no ping within a duration
15+
ErrConnectionLostPing = errors.New("connection lost ping")
1316
)

gotty/webtty/webtty.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/base64"
66
"encoding/json"
77
"github.com/pkg/errors"
8-
"log"
98
"os"
109
"strconv"
1110
"sync"
@@ -73,7 +72,7 @@ func (wt *WebTTY) Run(ctx context.Context) error {
7372
return errors.Wrapf(err, "failed to send initializing message")
7473
}
7574

76-
errs := make(chan error, 2)
75+
errs := make(chan error, 3)
7776

7877
go func() {
7978
errs <- func() error {
@@ -118,11 +117,10 @@ func (wt *WebTTY) Run(ctx context.Context) error {
118117
for {
119118
time.Sleep(time.Duration(30) * time.Second)
120119
if err != nil {
121-
return nil
120+
return err
122121
}
123122
if time.Now().After(wt.lastPingTime.Add(lostPingTimeout)) {
124-
log.Println("Connection lost ping.")
125-
return errors.Wrapf(err, "Connection lost ping.")
123+
return ErrConnectionLostPing
126124
}
127125
}
128126
}()

0 commit comments

Comments
 (0)