mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-23 09:31:02 +01:00
fixed possible memory leak for UDP stream
This commit is contained in:
@@ -5,6 +5,5 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
udpBufferSize = 8192
|
||||
streamStopListenTimeout = 1 * time.Second
|
||||
)
|
||||
|
||||
@@ -20,6 +20,7 @@ type (
|
||||
targetAddr *net.UDPAddr
|
||||
}
|
||||
UDPConn struct {
|
||||
key string
|
||||
src *net.UDPConn
|
||||
dst *net.UDPConn
|
||||
U.BidirectionalPipe
|
||||
@@ -29,6 +30,8 @@ type (
|
||||
|
||||
var NewUDPConnMap = F.NewMap[UDPConnMap]
|
||||
|
||||
const udpBufferSize = 8192
|
||||
|
||||
func NewUDPRoute(base *StreamRoute) StreamImpl {
|
||||
return &UDPRoute{
|
||||
StreamRoute: base,
|
||||
@@ -87,6 +90,7 @@ func (route *UDPRoute) Accept() (any, error) {
|
||||
return nil, err
|
||||
}
|
||||
conn = &UDPConn{
|
||||
key,
|
||||
srcConn,
|
||||
dstConn,
|
||||
U.NewBidirectionalPipe(route.ctx, sourceRWCloser{in, dstConn}, sourceRWCloser{in, srcConn}),
|
||||
@@ -99,7 +103,10 @@ func (route *UDPRoute) Accept() (any, error) {
|
||||
}
|
||||
|
||||
func (route *UDPRoute) Handle(c any) error {
|
||||
return c.(*UDPConn).Start()
|
||||
conn := c.(*UDPConn)
|
||||
err := conn.Start()
|
||||
route.connMap.Delete(conn.key)
|
||||
return err
|
||||
}
|
||||
|
||||
func (route *UDPRoute) CloseListeners() {
|
||||
|
||||
Reference in New Issue
Block a user