Fix three separate timeout bugs that caused tlsx to hang indefinitely for some hosts during TLS handshake (#819).
ztls tlsHandshakeWithTimeout() — broken selectHandshake() was called synchronously inside the select case expression:
// BEFORE (broken): Handshake() blocks, preventing ctx.Done() from ever firing
select {
case <-ctx.Done():
return error
case errChan <- tlsConn.Handshake(): // blocks here!
}
Fix: Run handshake in a goroutine so select can properly race between the handshake result and context cancellation:
// AFTER (fixed): Handshake runs concurrently, timeout actually works
go func() {
errChan <- tlsConn.Handshake()
}()
select {
case <-ctx.Done():
_ = tlsConn.Close() // unblock the goroutine
return error
case err := <-errChan:
return err
}
ztls EnumerateCiphers() — missing timeout contextUsed context.TODO() which has no deadline, making the timeout parameter completely ineffective:
// BEFORE: no timeout at all
c.tlsHandshakeWithTimeout(conn, context.TODO())
// AFTER: proper timeout from options
ctx, cancel := context.WithTimeout(context.Background(), timeout)
c.tlsHandshakeWithTimeout(conn, ctx)
tls EnumerateCiphers() — bare Handshake() with no contextUsed conn.Handshake() instead of conn.HandshakeContext(ctx), ignoring timeouts entirely:
// BEFORE: no timeout, can hang forever
conn.Handshake()
// AFTER: respects configured timeout
conn.HandshakeContext(ctx)
Build passes with zero errors:
$ go build ./...
(no output — success)
/claim #819
🤖 Generated with Claude Code
285729101
@285729101
youssefosama3820009-commits
@youssefosama3820009-commits
ProjectDiscovery
@projectdiscovery