Skip to content

Commit

Permalink
Fix UDP conn cleanup (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
luker983 authored Nov 11, 2023
1 parent 866677b commit 920d8ab
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/transport/udp/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
netipv6 "golang.org/x/net/ipv6"

"golang.zx2c4.com/wireguard/tun/netstack"
"gvisor.dev/gvisor/pkg/buffer"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/header"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
Expand Down Expand Up @@ -214,7 +213,7 @@ func handleConn(conn udpConn, port int, s *stack.Stack) {
pktChan, _ := connMapLookup(conn)
pkt := <-pktChan
// Exit if packet is empty, other goroutine wants us to close.
if pkt.IsNil() {
if pkt == nil {
return
}

Expand Down Expand Up @@ -252,15 +251,11 @@ func handleConn(conn udpConn, port int, s *stack.Stack) {
}
}

// Force closing of goroutine by reinjecting buffer (DecRef() to make nil pointer)
// Force closing of goroutine by injecting nil pointer
newConn.Close()
pktChan, ok := connMapLookup(conn)
if ok {
nilPkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
Payload: buffer.MakeWithData([]byte{}),
})
nilPkt.DecRef()
pktChan <- nilPkt
pktChan <- nil
}
return
}
Expand Down

0 comments on commit 920d8ab

Please sign in to comment.