mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 08:16:39 +00:00
[client] Fix UDP proxy to notify listener when remote conn closed (#4199)
* Fix UDP proxy to notify listener when remote conn closed * Fix sender tests to use t.Errorf for timeout assertions * Fix potential nil pointer
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package listener
|
||||
|
||||
import "sync"
|
||||
|
||||
type CloseListener struct {
|
||||
listener func()
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func NewCloseListener() *CloseListener {
|
||||
@@ -9,11 +12,21 @@ func NewCloseListener() *CloseListener {
|
||||
}
|
||||
|
||||
func (c *CloseListener) SetCloseListener(listener func()) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
c.listener = listener
|
||||
}
|
||||
|
||||
func (c *CloseListener) Notify() {
|
||||
if c.listener != nil {
|
||||
c.listener()
|
||||
c.mu.Lock()
|
||||
|
||||
if c.listener == nil {
|
||||
c.mu.Unlock()
|
||||
return
|
||||
}
|
||||
listener := c.listener
|
||||
c.mu.Unlock()
|
||||
|
||||
listener()
|
||||
}
|
||||
|
||||
@@ -183,6 +183,11 @@ func (p *WGUDPProxy) proxyToLocal(ctx context.Context) {
|
||||
for {
|
||||
n, err := p.remoteConnRead(ctx, buf)
|
||||
if err != nil {
|
||||
if ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
|
||||
p.closeListener.Notify()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user