Skip to content

fix(utils): return immediately on first successful dial#512

Merged
dwisiswant0 merged 1 commit intomainfrom
dwisiswant0/fix/utils/return-immediately-on-first-successful-dial
Dec 8, 2025
Merged

fix(utils): return immediately on first successful dial#512
dwisiswant0 merged 1 commit intomainfrom
dwisiswant0/fix/utils/return-immediately-on-first-successful-dial

Conversation

@dwisiswant0
Copy link
Member

re: projectdiscovery/nuclei#6631

fix(utils): return immediately on first successful dial

(*DialWrap).dialAllParallel() previously waited
for all goroutines to complete before returning,
even after a successful conn was established. This
caused 10+ second delays when dialing hostnames
that resolve to multiple IPs (e.g., localhost =>
127.0.0.1 + ::1) where some IPs have no listener.

Use a results channel with ctx cancellation to
return the first successful conn immediately.
Remaining dial attempts are cancelled via ctx, and
a background goroutine drains any in-flight
results to prevent leaks.

Found via block profile analysis showing
sync.WaitGroup.Wait blocking for the full dial
timeout duration.

Fixes #511.

`(*DialWrap).dialAllParallel()` previously waited
for all goroutines to complete before returning,
even after a successful conn was established. This
caused 10+ second delays when dialing hostnames
that resolve to multiple IPs (e.g., localhost =>
127.0.0.1 + ::1) where some IPs have no listener.

Use a results channel with ctx cancellation to
return the first successful conn immediately.
Remaining dial attempts are cancelled via ctx, and
a background goroutine drains any in-flight
results to prevent leaks.

Found via block profile analysis showing
`sync.WaitGroup.Wait` blocking for the full dial
timeout duration.

Fixes #511.

Signed-off-by: Dwi Siswanto <[email protected]>
@dwisiswant0 dwisiswant0 requested a review from Mzack9999 December 7, 2025 11:20
@dwisiswant0 dwisiswant0 merged commit 80e83c4 into main Dec 8, 2025
5 checks passed
@dwisiswant0 dwisiswant0 deleted the dwisiswant0/fix/utils/return-immediately-on-first-successful-dial branch December 8, 2025 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dialAllParallel waits for all dial attempts to complete, causing >10s delays when one IP times out

2 participants