error handling for closed socket

This commit is contained in:
Suyono 2025-04-23 20:46:57 +10:00
parent d2f02d9782
commit 78cab7a871

View File

@ -3,6 +3,7 @@ package netbounce
import (
"bytes"
"context"
"errors"
"fmt"
"net"
"sync"
@ -231,7 +232,19 @@ func (b *backendUDP) udpBackend2Client(wg *sync.WaitGroup, rel udpRel) {
udpBackendLoop:
for {
if n, _, err = rel.backend.ReadFrom(buf); err != nil {
//TODO: error handling
select {
case <-rel.ctx.Done():
break udpBackendLoop
default:
}
if errors.Is(err, net.ErrClosed) { //TODO: implement this error handling to all socket read/write operation
rel.ctxCancel()
break udpBackendLoop
}
log.Error().Err(err).Str(CONNECTION, rel.clientAddr).Str(DIRECTION, BACKEND_TO_CLIENT).Msg("udpBackend2Client: read from udp")
continue udpBackendLoop
}
clientAddr = rel.clientAddr