From a6b3ebe28aebf4bc731f6e311672bfc0019e244e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rytis=20Karpu=C5=A1ka?= Date: Tue, 18 Jun 2024 17:36:56 +0300 Subject: [PATCH] Add more logging when read from tun failure happens --- device/send.go | 5 +---- tun/tun_windows.go | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/device/send.go b/device/send.go index 1acf23025..22de4e3c3 100644 --- a/device/send.go +++ b/device/send.go @@ -10,7 +10,6 @@ import ( "encoding/binary" "errors" "net" - "os" "sync" "time" @@ -310,9 +309,7 @@ func (device *Device) RoutineReadFromTUN() { continue } if !device.isClosed() { - if !errors.Is(readErr, os.ErrClosed) { - device.log.Errorf("Failed to read packet from TUN device: %v", readErr) - } + device.log.Errorf("Failed to read packet from TUN device: %v", readErr) go device.Close() } return diff --git a/tun/tun_windows.go b/tun/tun_windows.go index 2af8e3e92..3545ef272 100644 --- a/tun/tun_windows.go +++ b/tun/tun_windows.go @@ -149,13 +149,13 @@ func (tun *NativeTun) Read(bufs [][]byte, sizes []int, offset int) (int, error) defer tun.running.Done() retry: if tun.close.Load() { - return 0, os.ErrClosed + return 0, errors.New("Tunnel is being shutdown at the startup of reading of packets") } start := nanotime() shouldSpin := tun.rate.current.Load() >= spinloopRateThreshold && uint64(start-tun.rate.nextStartTime.Load()) <= rateMeasurementGranularity*2 for { if tun.close.Load() { - return 0, os.ErrClosed + return 0, errors.New("Tunnel is being shutdown while reading packets") } packet, err := tun.session.ReceivePacket() switch err { @@ -173,7 +173,7 @@ retry: procyield(1) continue case windows.ERROR_HANDLE_EOF: - return 0, os.ErrClosed + return 0, errors.New("Driver indicated EOF while reading from tunnel") case windows.ERROR_INVALID_DATA: return 0, errors.New("Send ring corrupt") }