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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user