api/handler/rpc: not log error on client disconnect (#1482)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
032a936150
commit
281cced325
23
stream.go
23
stream.go
@ -135,9 +135,19 @@ func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request,
|
||||
|
||||
// receive from stream and send to client
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-stream.Context().Done():
|
||||
return
|
||||
default:
|
||||
// read backend response body
|
||||
buf, err := rsp.Read()
|
||||
if err != nil {
|
||||
// wants to avoid import grpc/status.Status
|
||||
if strings.Contains(err.Error(), "context canceled") {
|
||||
return
|
||||
}
|
||||
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
|
||||
logger.Error(err)
|
||||
}
|
||||
@ -159,6 +169,7 @@ func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// writeLoop
|
||||
func writeLoop(rw io.ReadWriter, stream client.Stream) {
|
||||
@ -166,13 +177,23 @@ func writeLoop(rw io.ReadWriter, stream client.Stream) {
|
||||
defer stream.Close()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-stream.Context().Done():
|
||||
return
|
||||
default:
|
||||
buf, op, err := wsutil.ReadClientData(rw)
|
||||
if err != nil {
|
||||
wserr := err.(wsutil.ClosedError)
|
||||
switch wserr.Code {
|
||||
case ws.StatusNormalClosure, ws.StatusNoStatusRcvd:
|
||||
return
|
||||
default:
|
||||
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
|
||||
logger.Error(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
switch op {
|
||||
default:
|
||||
// not relevant
|
||||
@ -184,7 +205,6 @@ func writeLoop(rw io.ReadWriter, stream client.Stream) {
|
||||
// default to trying json
|
||||
// if the extracted payload isn't empty lets use it
|
||||
request := &raw.Frame{Data: buf}
|
||||
|
||||
if err := stream.Send(request); err != nil {
|
||||
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
|
||||
logger.Error(err)
|
||||
@ -193,6 +213,7 @@ func writeLoop(rw io.ReadWriter, stream client.Stream) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func isStream(r *http.Request, srv *api.Service) bool {
|
||||
// check if it's a web socket
|
||||
|
Loading…
Reference in New Issue
Block a user