Skip to content

Commit

Permalink
Add more logging when read from tun failure happens
Browse files Browse the repository at this point in the history
  • Loading branch information
Jauler committed Jun 18, 2024
1 parent 590352b commit f97c792
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions device/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,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
Expand Down
6 changes: 3 additions & 3 deletions tun/tun_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}
Expand Down

0 comments on commit f97c792

Please sign in to comment.