Fix: tls handshake requires a timeout (#1893)

This commit is contained in:
thank243
2022-01-15 19:33:21 +08:00
committed by GitHub
parent 8f3385bbb6
commit 9732efe938
4 changed files with 23 additions and 3 deletions

View File

@ -1,8 +1,11 @@
package vmess
import (
"context"
"crypto/tls"
"net"
C "github.com/Dreamacro/clash/constant"
)
type TLSConfig struct {
@ -19,6 +22,10 @@ func StreamTLSConn(conn net.Conn, cfg *TLSConfig) (net.Conn, error) {
}
tlsConn := tls.Client(conn, tlsConfig)
err := tlsConn.Handshake()
// fix tls handshake not timeout
ctx, cancel := context.WithTimeout(context.Background(), C.DefaultTLSTimeout)
defer cancel()
err := tlsConn.HandshakeContext(ctx)
return tlsConn, err
}