TUN-6691: Properly error check for net.ErrClosed
UDP session would check if the socket was closed before returning but the net.ErrClosed could be wrapped in another error.
This commit is contained in:
parent
59f5b0df83
commit
fc5749328d
|
@ -2,6 +2,7 @@ package datagramsession
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
@ -49,10 +50,10 @@ func (s *Session) Serve(ctx context.Context, closeAfterIdle time.Duration) (clos
|
||||||
readBuffer := make([]byte, maxPacketSize)
|
readBuffer := make([]byte, maxPacketSize)
|
||||||
for {
|
for {
|
||||||
if closeSession, err := s.dstToTransport(readBuffer); err != nil {
|
if closeSession, err := s.dstToTransport(readBuffer); err != nil {
|
||||||
if err != net.ErrClosed {
|
if errors.Is(err, net.ErrClosed) {
|
||||||
s.log.Error().Err(err).Msg("Failed to send session payload from destination to transport")
|
s.log.Debug().Msg("Destination connection closed")
|
||||||
} else {
|
} else {
|
||||||
s.log.Debug().Msg("Session cannot read from destination because the connection is closed")
|
s.log.Error().Err(err).Msg("Failed to send session payload from destination to transport")
|
||||||
}
|
}
|
||||||
if closeSession {
|
if closeSession {
|
||||||
s.closeChan <- err
|
s.closeChan <- err
|
||||||
|
|
Loading…
Reference in New Issue