fix(agent/stream): handle EOF error in UDP server connection

- Updated error handling in the UDP server to ignore io.EOF errors when reading from client connections.
- Added a check to return early if no bytes are read from the client connection.
- Ensured proper closure of tcpListener in the main.go file during cancellation.
This commit is contained in:
yusing
2026-01-07 21:10:47 +08:00
parent d7361c6f52
commit 5048326c20
2 changed files with 6 additions and 2 deletions

View File

@@ -192,9 +192,9 @@ Tips:
{
subtask := t.Subtask("agent-tls-mux", true)
t.OnCancel("stop_mux", func() {
_ = tcpListener.Close()
_ = httpLn.Close()
_ = streamLn.Close()
_ = tcpListener.Close()
})
go func() {
defer subtask.Finish(subtask.FinishCause())

View File

@@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"errors"
"io"
"net"
"time"
@@ -119,10 +120,13 @@ func (s *UDPServer) handleDTLSConnection(clientConn net.Conn) {
return
default:
n, err := clientConn.Read(buf)
if err != nil {
if err != nil && !errors.Is(err, io.EOF) {
s.logger(clientConn).Err(err).Msg("failed to read from client")
return
}
if n == 0 {
return
}
if _, err := dstConn.Write(buf[:n]); err != nil {
s.logger(clientConn).Err(err).Msgf("failed to write %d bytes to destination", n)
return