fix(ztls): move handshake to goroutine to prevent indefinite hang#966
fix(ztls): move handshake to goroutine to prevent indefinite hang#966allornothingai wants to merge 2 commits intoprojectdiscovery:mainfrom
Conversation
Neo - PR Security ReviewNo security issues found Highlights
Comment |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
WalkthroughChanged Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Function as tlsHandshakeWithTimeout
participant Goroutine as handshakeGoroutine
participant TLS as tls.Conn
participant Context as ctx
Caller->>Function: call(ctx, tlsConn)
Function->>Goroutine: start goroutine -> Handshake()
Goroutine->>TLS: Handshake()
TLS-->>Goroutine: err (or nil / tls.ErrCertsOnly)
Goroutine-->>Function: send err on errChan
alt ctx cancels before err
Context-->>Function: ctx.Done()
Function-->>Caller: return tagged Wrap(ctx.Err())
else err received first
Function-->>Caller: receive err, convert tls.ErrCertsOnly -> nil, return err
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/tlsx/ztls/ztls.go (1)
324-324: Consider placingctxas the first parameter.Go convention is to pass
context.Contextas the first parameter of a function. This is a minor style nit.-func (c *Client) tlsHandshakeWithTimeout(tlsConn *tls.Conn, ctx context.Context) error { +func (c *Client) tlsHandshakeWithTimeout(ctx context.Context, tlsConn *tls.Conn) error {If you accept this change, also update the call sites at lines 143 and 260.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/tlsx/ztls/ztls.go` at line 324, Change the method signature to accept context.Context as the first parameter: rename func (c *Client) tlsHandshakeWithTimeout(tlsConn *tls.Conn, ctx context.Context) error to func (c *Client) tlsHandshakeWithTimeout(ctx context.Context, tlsConn *tls.Conn) error, and update all call sites to pass the ctx first (replace calls like tlsHandshakeWithTimeout(tlsConn, ctx) with tlsHandshakeWithTimeout(ctx, tlsConn)); ensure imports and any references (tlsHandshakeWithTimeout, Client) compile after the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/tlsx/ztls/ztls.go`:
- Line 324: Change the method signature to accept context.Context as the first
parameter: rename func (c *Client) tlsHandshakeWithTimeout(tlsConn *tls.Conn,
ctx context.Context) error to func (c *Client) tlsHandshakeWithTimeout(ctx
context.Context, tlsConn *tls.Conn) error, and update all call sites to pass the
ctx first (replace calls like tlsHandshakeWithTimeout(tlsConn, ctx) with
tlsHandshakeWithTimeout(ctx, tlsConn)); ensure imports and any references
(tlsHandshakeWithTimeout, Client) compile after the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d0c210f8-2cce-423d-8af1-b8520925c862
📒 Files selected for processing (1)
pkg/tlsx/ztls/ztls.go
This PR fixes an indefinite hang in the ztls client.
Root Cause: The method was being called synchronously within a case. In Go, case expressions are evaluated before the select blocks, meaning the handshake was executed on the main goroutine, effectively bypassing the context timeout if the network connection hung.
Fix: Moved the call to a separate goroutine and used the block to wait for either the result or the context cancellation.
Payout Wallet (EVM):
0x0c67cbE9e30c66267975eE2D74Eb88036CA65e9FPayout Wallet (SOL):
3hLpMvUUS685bZz2PzR6vWeA37UrdKq924s7yLMB47eZSummary by CodeRabbit
Bug Fixes
Refactor