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

Suppress Read() error on closing websocket-proxy connection #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions api/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"net/http"
"strconv"
"strings"

"github.com/gorilla/websocket"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -66,13 +67,21 @@ func PassThrough(w http.ResponseWriter, r *http.Request, host string, port int)
buf := make([]byte, 1024)
size, err := remoteSrv.Read(buf)
if err != nil {
if strings.HasSuffix(err.Error(), ": use of closed network connection") {
log.Debug("node->gnt-cc: the remote side has closed the connection")
return
}
log.Warningf("node->gnt-cc: failed to read from remote socket: %s", err)
return
}
data := buf[:size]
log.Debugf("node->gnt-cc: Writing %d Bytes to websocket", len(data))
err = conn.WriteMessage(websocket.BinaryMessage, data)
if err != nil {
if strings.HasSuffix(err.Error(), ": use of closed network connection") {
log.Debug("node->gnt-cc: the remote side has closed the connection")
return
}
log.Warningf("node->gnt-cc: failed to write to websocket: %s", err)
return
}
Expand All @@ -92,13 +101,21 @@ func PassThrough(w http.ResponseWriter, r *http.Request, host string, port int)
return
}
if err != nil {
if strings.HasSuffix(err.Error(), ": use of closed network connection") {
log.Debug("node->gnt-cc: the remote side has closed the connection")
return
}
log.Warningf("gnt-cc->node: failed to read websocket message: %s", err)
return
}
checkAndLogMessage(msgType)
log.Debugf("gnt-cc->node: Writing %d Bytes to remote socket", len(message))
_, err = remoteSrv.Write(message)
if err != nil {
if strings.HasSuffix(err.Error(), ": use of closed network connection") {
log.Debug("node->gnt-cc: the remote side has closed the connection")
return
}
log.Warningf("gnt-cc->node: failed to write to remote socket: %s", err)
return
}
Expand Down