1
0
mirror of https://github.com/fumiama/terasu-cloudflared.git synced 2026-06-12 22:40:32 +08:00

TUN-9882: Add write deadline for UDP origin writes

Add a deadline for origin writes as a preventative measure in the case that the kernel blocks any writes for too long.
In the case that the socket exceeds the write deadline, the datagram will be dropped.

Closes TUN-9882
This commit is contained in:
Devin Carr
2025-10-07 19:54:42 -07:00
parent 1fb466941a
commit 51c5ef726c
2 changed files with 25 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net"
"os"
"sync"
"sync/atomic"
"time"
@@ -241,6 +242,11 @@ func (s *session) writeLoop() {
case payload := <-s.writeChan:
n, err := s.origin.Write(payload)
if err != nil {
// Check if this is a write deadline exceeded to the connection
if errors.Is(err, os.ErrDeadlineExceeded) {
s.log.Warn().Err(err).Msg("flow (write) deadline exceeded: dropping packet")
continue
}
if isConnectionClosed(err) {
s.log.Debug().Msgf("flow (write) connection closed: %v", err)
}