From 42d77f24dca2d32c5f622c52cde3b1b1a67bb710 Mon Sep 17 00:00:00 2001 From: patterniha <71074308+patterniha@users.noreply.github.com> Date: Sat, 23 Aug 2025 02:26:04 +0330 Subject: [PATCH] fix --- app/proxyman/inbound/worker.go | 4 ++-- proxy/freedom/freedom.go | 4 ++-- transport/internet/udp/dispatcher.go | 22 ++++++++++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/proxyman/inbound/worker.go b/app/proxyman/inbound/worker.go index 40c8bc15..ebe4bc89 100644 --- a/app/proxyman/inbound/worker.go +++ b/app/proxyman/inbound/worker.go @@ -382,7 +382,7 @@ func (w *udpWorker) clean() error { } for addr, conn := range w.activeConn { - if nowSec-atomic.LoadInt64(&conn.lastActivityTime) > 2*60 { + if nowSec-atomic.LoadInt64(&conn.lastActivityTime) > 60 { if !conn.inactive { conn.setInactive() delete(w.activeConn, addr) @@ -409,7 +409,7 @@ func (w *udpWorker) Start() error { w.cone = w.ctx.Value("cone").(bool) w.checker = &task.Periodic{ - Interval: time.Minute, + Interval: 30 * time.Second, Execute: w.clean, } diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index 0e9937e3..f8d64812 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -73,7 +73,7 @@ func isValidAddress(addr *net.IPOrDomain) bool { } a := addr.AsAddress() - return a != net.AnyIP + return a != net.AnyIP && a != net.AnyIPv6 } // Process implements proxy.Outbound. @@ -418,7 +418,7 @@ func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error { } } } - destAddr, _ := net.ResolveUDPAddr("udp", b.UDP.NetAddr()) + destAddr := b.UDP.RawNetAddr() if destAddr == nil { b.Release() continue diff --git a/transport/internet/udp/dispatcher.go b/transport/internet/udp/dispatcher.go index 9f5144ec..d383e316 100644 --- a/transport/internet/udp/dispatcher.go +++ b/transport/internet/udp/dispatcher.go @@ -22,17 +22,24 @@ type ResponseCallback func(ctx context.Context, packet *udp.Packet) type connEntry struct { link *transport.Link - timer signal.ActivityUpdater + timer *signal.ActivityTimer cancel context.CancelFunc closed bool } func (c *connEntry) Close() error { + c.timer.SetTimeout(0) + return nil +} + +func (c *connEntry) terminate() { + if c.closed { + panic("terminate called more than once") + } c.closed = true c.cancel() common.Interrupt(c.link.Reader) common.Close(c.link.Writer) - return nil } type Dispatcher struct { @@ -41,6 +48,7 @@ type Dispatcher struct { dispatcher routing.Dispatcher callback ResponseCallback callClose func() error + closed bool } func NewDispatcher(dispatcher routing.Dispatcher, callback ResponseCallback) *Dispatcher { @@ -53,6 +61,7 @@ func NewDispatcher(dispatcher routing.Dispatcher, callback ResponseCallback) *Di func (v *Dispatcher) RemoveRay() { v.Lock() defer v.Unlock() + v.closed = true if v.conn != nil { v.conn.Close() v.conn = nil @@ -63,6 +72,10 @@ func (v *Dispatcher) getInboundRay(ctx context.Context, dest net.Destination) (* v.Lock() defer v.Unlock() + if v.closed { + return nil, errors.New("dispatcher is closed") + } + if v.conn != nil { if v.conn.closed { v.conn = nil @@ -85,11 +98,8 @@ func (v *Dispatcher) getInboundRay(ctx context.Context, dest net.Destination) (* link: link, cancel: cancel, } - entryClose := func() { - entry.Close() - } - entry.timer = signal.CancelAfterInactivity(ctx, entryClose, time.Minute) + entry.timer = signal.CancelAfterInactivity(ctx, entry.terminate, 30*time.Second) // The UDP timeout is set to 30 seconds in most NAT configurations v.conn = entry go handleInput(ctx, entry, dest, v.callback, v.callClose) return entry, nil