hotfix: fix use too much memory (#710)

This commit is contained in:
naison
2025-08-28 20:25:26 +08:00
committed by GitHub
parent 0548c5a8a0
commit 2d23a46d33
2 changed files with 7 additions and 3 deletions

View File

@@ -36,6 +36,7 @@ func (h *gvisorLocalHandler) Run(ctx context.Context) {
// for support ipv6 skip checksum
// vendor/gvisor.dev/gvisor/pkg/tcpip/stack/nic.go:763
endpoint.LinkEPCapabilities = stack.CapabilityRXChecksumOffload
defer endpoint.Close()
go func() {
defer util.HandleCrash()
readFromGvisorInboundWriteToEndpoint(ctx, h.gvisorInbound, endpoint)

View File

@@ -43,8 +43,11 @@ type ClientDevice struct {
func (d *ClientDevice) handlePacket(ctx context.Context, forward *Forwarder) {
for ctx.Err() == nil {
func() {
subCtx, cancelFunc := context.WithCancel(ctx)
defer cancelFunc()
defer time.Sleep(time.Second * 2)
conn, err := forwardConn(ctx, forward)
conn, err := forwardConn(subCtx, forward)
if err != nil {
plog.G(ctx).Errorf("Failed to get remote conn from %s -> %s: %s", d.tun.LocalAddr(), forward.node.Remote, err)
return
@@ -52,8 +55,8 @@ func (d *ClientDevice) handlePacket(ctx context.Context, forward *Forwarder) {
defer conn.Close()
errChan := make(chan error, 2)
go readFromConn(ctx, conn, d.tunInbound, d.tunOutbound, errChan)
go writeToConn(ctx, conn, d.tunInbound, errChan)
go readFromConn(subCtx, conn, d.tunInbound, d.tunOutbound, errChan)
go writeToConn(subCtx, conn, d.tunInbound, errChan)
select {
case err = <-errChan: