Skip to content

Commit 5cbfa3a

Browse files
committed
fix: Close client tunnel on network error
1 parent 2e76665 commit 5cbfa3a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

internal/server/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,9 @@ func (ms *MmarServer) processTunnelMessages(ct *ClientTunnel) {
425425
tunnelMsg, err := ct.ReceiveMessage()
426426
if err != nil {
427427
logger.Log(constants.DEFAULT_COLOR, fmt.Sprintf("Receive Message from client tunnel errored: %v", err))
428-
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, net.ErrClosed) {
428+
if utils.NetworkError(err) {
429429
// If error with connection, stop processing messages
430+
ms.closeClientTunnel(ct)
430431
return
431432
}
432433
continue

internal/utils/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import (
44
"crypto/sha256"
55
"crypto/subtle"
66
"encoding/hex"
7+
"errors"
78
"fmt"
9+
"io"
810
"net"
911
"os"
1012
"strings"
13+
"syscall"
1114

1215
"github.com/yusuf-musleh/mmar/constants"
1316
)
@@ -104,3 +107,10 @@ func ValidCredentials(username string, password string) bool {
104107
validPassword := subtle.ConstantTimeCompare(passwordHash[:], passwordDecodedHash) == 1
105108
return validUsername && validPassword
106109
}
110+
111+
func NetworkError(err error) bool {
112+
return errors.Is(err, io.EOF) ||
113+
errors.Is(err, io.ErrUnexpectedEOF) ||
114+
errors.Is(err, net.ErrClosed) ||
115+
errors.Is(err, syscall.ECONNRESET)
116+
}

0 commit comments

Comments
 (0)