From 54d954323f15a9b916a53163637f3d5d2f54e60f Mon Sep 17 00:00:00 2001 From: Murtaza Aliakbar Date: Sun, 1 Dec 2024 13:06:06 +0530 Subject: [PATCH] ipn/wg: release read-lock before return --- intra/ipn/wg/wgconn.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/intra/ipn/wg/wgconn.go b/intra/ipn/wg/wgconn.go index 544343ac..76ed9c59 100644 --- a/intra/ipn/wg/wgconn.go +++ b/intra/ipn/wg/wgconn.go @@ -332,6 +332,7 @@ func (bind *StdNetBind) Close() error { func (s *StdNetBind) makeReceiveFn(uc net.PacketConn) conn.ReceiveFunc { // github.com/WireGuard/wireguard-go/blob/469159ecf/device/device.go#L531 return func(bufs [][]byte, sizes []int, eps []conn.Endpoint) (n int, err error) { + defer core.Recover(core.Exit11, "wgconn.recv."+s.id) defer func() { s.observer("r", err) }() @@ -373,6 +374,7 @@ func timedout(err error) bool { } func (s *StdNetBind) Send(buf [][]byte, peer conn.Endpoint) (err error) { + defer core.Recover(core.Exit11, "wgconn.send."+s.id) defer func() { s.observer("w", err) }() @@ -547,18 +549,20 @@ func (s *StdNetBind) asEndpoint(ap net.Addr) conn.Endpoint { return invalidStdNetEndpoint } s.epmu.RLock() - if ep, ok := s.eps[ap]; ok { + ep, ok := s.eps[ap] + s.epmu.RUnlock() + + if ok { return ep } - s.epmu.RUnlock() s.epmu.Lock() defer s.epmu.Unlock() - if ep, ok := s.eps[ap]; ok { + ep, ok = s.eps[ap] + if ok { return ep } - var ep StdNetEndpoint if tcp, ok := ap.(*net.TCPAddr); ok { ipp := tcp.AddrPort() ep = StdNetEndpoint{ipp, udpaddr(ipp)}