diff --git a/internal/server/main.go b/internal/server/main.go index 96ccabc..fee090f 100644 --- a/internal/server/main.go +++ b/internal/server/main.go @@ -425,8 +425,9 @@ func (ms *MmarServer) processTunnelMessages(ct *ClientTunnel) { tunnelMsg, err := ct.ReceiveMessage() if err != nil { logger.Log(constants.DEFAULT_COLOR, fmt.Sprintf("Receive Message from client tunnel errored: %v", err)) - if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, net.ErrClosed) { + if utils.NetworkError(err) { // If error with connection, stop processing messages + ms.closeClientTunnel(ct) return } continue diff --git a/internal/utils/main.go b/internal/utils/main.go index 5156da9..a35d885 100644 --- a/internal/utils/main.go +++ b/internal/utils/main.go @@ -4,10 +4,13 @@ import ( "crypto/sha256" "crypto/subtle" "encoding/hex" + "errors" "fmt" + "io" "net" "os" "strings" + "syscall" "github.com/yusuf-musleh/mmar/constants" ) @@ -104,3 +107,10 @@ func ValidCredentials(username string, password string) bool { validPassword := subtle.ConstantTimeCompare(passwordHash[:], passwordDecodedHash) == 1 return validUsername && validPassword } + +func NetworkError(err error) bool { + return errors.Is(err, io.EOF) || + errors.Is(err, io.ErrUnexpectedEOF) || + errors.Is(err, net.ErrClosed) || + errors.Is(err, syscall.ECONNRESET) +}