Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't log "expected" websocket errors #1024

Merged
merged 3 commits into from
Feb 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/api_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ func handleWebsocket(
go func(c *websocket.Conn) {
for { // just discard everything the browser sends
if _, _, err := c.NextReader(); err != nil {
log.Println("err:", err)
if !xfer.IsExpectedWSCloseError(err) {
log.Println("err:", err)
}
close(quit)
break
}
Expand All @@ -111,7 +113,9 @@ func handleWebsocket(
previousTopo = newTopo

if err := conn.SetWriteDeadline(time.Now().Add(websocketTimeout)); err != nil {
log.Println("err:", err)
if !xfer.IsExpectedWSCloseError(err) {
log.Println("err:", err)
}
return
}

Expand Down
4 changes: 3 additions & 1 deletion app/controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func handleProbeWS(cr ControlRouter) CtxHandlerFunc {
return
}
defer cr.Deregister(ctx, probeID, id)
codec.WaitForReadError()
if err := codec.WaitForReadError(); err != nil && !xfer.IsExpectedWSCloseError(err) {
log.Printf("Error reading from probe %s control websocket: %v", probeID, err)
}
}
}
6 changes: 5 additions & 1 deletion app/pipes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/gorilla/mux"
"golang.org/x/net/context"

"github.com/weaveworks/scope/common/xfer"
)

// RegisterPipeRoutes registers the pipe routes
Expand Down Expand Up @@ -41,7 +43,9 @@ func handlePipeWs(pr PipeRouter, end End) CtxHandlerFunc {
defer conn.Close()

log.Infof("Pipe success %s (%d)", id, end)
pipe.CopyToWebsocket(endIO, conn)
if err := pipe.CopyToWebsocket(endIO, conn); err != nil && !xfer.IsExpectedWSCloseError(err) {
log.Printf("Error copying to pipe %s (%d) websocket: %v", id, end, err)
}
}
}

Expand Down
9 changes: 5 additions & 4 deletions common/xfer/controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ func ResponseError(err error) Response {
type JSONWebsocketCodec struct {
sync.Mutex
conn *websocket.Conn
err chan struct{}
err chan error
}

// NewJSONWebsocketCodec makes a new JSONWebsocketCodec
func NewJSONWebsocketCodec(conn *websocket.Conn) *JSONWebsocketCodec {
return &JSONWebsocketCodec{
conn: conn,
err: make(chan struct{}),
err: make(chan error, 1),
}
}

// WaitForReadError blocks until any read on this codec returns an error.
// This is useful to know when the server has disconnected from the client.
func (j *JSONWebsocketCodec) WaitForReadError() {
<-j.err
func (j *JSONWebsocketCodec) WaitForReadError() error {
return <-j.err
}

// WriteRequest implements rpc.ClientCodec
Expand Down Expand Up @@ -113,6 +113,7 @@ func (j *JSONWebsocketCodec) WriteResponse(r *rpc.Response, v interface{}) error
func (j *JSONWebsocketCodec) readMessage(v interface{}) (*Message, error) {
m := Message{Value: v}
if err := ReadJSONfromWS(j.conn, &m); err != nil {
j.err <- err
close(j.err)
return nil, err
}
Expand Down
11 changes: 11 additions & 0 deletions common/xfer/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ import (
"github.com/ugorji/go/codec"
)

// IsExpectedWSCloseError returns boolean indicating whether the error is a
// clean disconnection.
func IsExpectedWSCloseError(err error) bool {
return websocket.IsCloseError(
err,
websocket.CloseNormalClosure,
websocket.CloseGoingAway,
websocket.CloseNoStatusReceived,
)
}

// WriteJSONtoWS writes the JSON encoding of v to the connection.
func WriteJSONtoWS(c *websocket.Conn, v interface{}) error {
w, err := c.NextWriter(websocket.TextMessage)
Expand Down
38 changes: 30 additions & 8 deletions vendor/github.com/gorilla/websocket/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 97 additions & 4 deletions vendor/github.com/gorilla/websocket/client_server_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 20 additions & 12 deletions vendor/github.com/gorilla/websocket/client_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading