mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
fix too many open files bug
This commit is contained in:
@@ -4,11 +4,10 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/wencaiwulue/kubevpn/util"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type fakeUDPTunConnector struct {
|
||||
@@ -236,3 +235,21 @@ func (c *fakeUDPTunnelConn) WriteTo(b []byte, addr net.Addr) (n int, err error)
|
||||
}
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
func (c *fakeUDPTunnelConn) Close() error {
|
||||
return c.Conn.Close()
|
||||
}
|
||||
|
||||
func (c *fakeUDPTunnelConn) CloseWrite() error {
|
||||
if cc, ok := c.Conn.(interface{ CloseWrite() error }); ok {
|
||||
return cc.CloseWrite()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *fakeUDPTunnelConn) CloseRead() error {
|
||||
if cc, ok := c.Conn.(interface{ CloseRead() error }); ok {
|
||||
return cc.CloseRead()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -135,7 +135,15 @@ func (h *tunHandler) findRouteFor(dst net.IP) net.Addr {
|
||||
|
||||
func (h *tunHandler) transportTun(tun net.Conn, conn net.PacketConn, raddr net.Addr) error {
|
||||
errChan := make(chan error, 2)
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
if c, ok := conn.(interface{ CloseRead() error }); ok {
|
||||
_ = c.CloseRead()
|
||||
}
|
||||
if c, ok := conn.(interface{ CloseWrite() error }); ok {
|
||||
_ = c.CloseWrite()
|
||||
}
|
||||
_ = conn.Close()
|
||||
}()
|
||||
ctx, cancelFunc := context.WithCancel(context.Background())
|
||||
remote.CancelFunctions = append(remote.CancelFunctions, cancelFunc)
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user