diff --git a/app/controls.go b/app/controls.go index 791d922c76..00eb43d208 100644 --- a/app/controls.go +++ b/app/controls.go @@ -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) + } } } diff --git a/app/pipes.go b/app/pipes.go index 9f5cb71cc5..7ca90b5434 100644 --- a/app/pipes.go +++ b/app/pipes.go @@ -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 @@ -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) + } } } diff --git a/common/xfer/controls.go b/common/xfer/controls.go index aba3c71d4e..cfb0d1dde5 100644 --- a/common/xfer/controls.go +++ b/common/xfer/controls.go @@ -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 @@ -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 }