diff --git a/common/network/dialer.go b/common/network/dialer.go index 7c3f3e2..0dbebf4 100644 --- a/common/network/dialer.go +++ b/common/network/dialer.go @@ -13,10 +13,6 @@ type Dialer interface { ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) } -type PayloadDialer interface { - DialPayloadContext(ctx context.Context, network string, destination M.Socksaddr, payload [][]byte) (net.Conn, error) -} - type ParallelDialer interface { Dialer DialParallel(ctx context.Context, network string, destination M.Socksaddr, destinationAddresses []netip.Addr) (net.Conn, error) diff --git a/common/network/handshake.go b/common/network/handshake.go index 5f13492..d2203e0 100644 --- a/common/network/handshake.go +++ b/common/network/handshake.go @@ -36,7 +36,13 @@ func ReportHandshakeFailure(reporter any, err error) error { func CloseOnHandshakeFailure(reporter any, onClose CloseHandlerFunc, err error) error { if err != nil { if handshakeConn, isHandshakeConn := common.Cast[HandshakeFailure](reporter); isHandshakeConn { - err = E.Append(err, handshakeConn.HandshakeFailure(err), func(err error) error { + hErr := handshakeConn.HandshakeFailure(err) + err = E.Append(err, hErr, func(err error) error { + if closer, isCloser := reporter.(io.Closer); isCloser { + err = E.Append(err, closer.Close(), func(err error) error { + return E.Cause(err, "close") + }) + } return E.Cause(err, "write handshake failure") }) } else { diff --git a/protocol/socks/lazy.go b/protocol/socks/lazy.go index 3468981..f98ac3d 100644 --- a/protocol/socks/lazy.go +++ b/protocol/socks/lazy.go @@ -2,6 +2,7 @@ package socks import ( "net" + "os" "github.com/sagernet/sing/common/buf" "github.com/sagernet/sing/common/bufio" @@ -48,7 +49,7 @@ func (c *LazyConn) ConnHandshakeSuccess(conn net.Conn) error { func (c *LazyConn) HandshakeFailure(err error) error { if c.responseWritten { - return nil + return os.ErrInvalid } defer func() { c.responseWritten = true @@ -130,7 +131,7 @@ func (c *LazyAssociatePacketConn) HandshakeSuccess() error { func (c *LazyAssociatePacketConn) HandshakeFailure(err error) error { if c.responseWritten { - return nil + return os.ErrInvalid } defer func() { c.responseWritten = true