Skip to content
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
3 changes: 2 additions & 1 deletion internal/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions internal/utils/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import (
"crypto/sha256"
"crypto/subtle"
"encoding/hex"
"errors"
"fmt"
"io"
"net"
"os"
"strings"
"syscall"

"github.com/yusuf-musleh/mmar/constants"
)
Expand Down Expand Up @@ -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)
}
Loading