Fix copy pipe

This commit is contained in:
世界 2022-10-20 10:57:57 +08:00
parent 7e0958b4ac
commit 95c03c9373
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4

View File

@ -3,6 +3,7 @@ package outbound
import ( import (
"context" "context"
"net" "net"
"os"
"runtime" "runtime"
"time" "time"
@ -136,6 +137,7 @@ func CopyEarlyConn(ctx context.Context, conn net.Conn, serverConn net.Conn) erro
_payload := buf.StackNew() _payload := buf.StackNew()
payload := common.Dup(_payload) payload := common.Dup(_payload)
err := conn.SetReadDeadline(time.Now().Add(C.ReadPayloadTimeout)) err := conn.SetReadDeadline(time.Now().Add(C.ReadPayloadTimeout))
if err != os.ErrInvalid {
if err != nil { if err != nil {
return err return err
} }
@ -148,10 +150,12 @@ func CopyEarlyConn(ctx context.Context, conn net.Conn, serverConn net.Conn) erro
payload.Release() payload.Release()
return err return err
} }
}
_, err = serverConn.Write(payload.Bytes()) _, err = serverConn.Write(payload.Bytes())
if err != nil { if err != nil {
return N.HandshakeFailure(conn, err) return N.HandshakeFailure(conn, err)
} }
runtime.KeepAlive(_payload) runtime.KeepAlive(_payload)
payload.Release()
return bufio.CopyConn(ctx, conn, serverConn) return bufio.CopyConn(ctx, conn, serverConn)
} }