Skip to content

fix(jarm): stop the connection pool from spinning and leaking on shutdown - #2802

Merged
Mzack9999 merged 3 commits into
projectdiscovery:devfrom
hakarrr:fix-jarm-onetimepool
Dec 2, 2026
Merged

Mzack9999 merged 3 commits into
projectdiscovery:devfrom
hakarrr:fix-jarm-onetimepool

Conversation

@hakarrr

@hakarrr hakarrr commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Two defects in oneTimePool.Run, both visible during -jarm scans against many hosts:

  1. CPU spin on unreachable targets. When the target refuses or drops the connection, Dial fails and the loop retries immediately with no backoff. One goroutine per unreachable host then runs at full CPU until the pool context times out (duration * poolCount seconds per host). With -jarm across hundreds of dead hosts this pins every core.
  2. Permanent goroutine leak on a full pool. The dialed connection is offered with a bare channel send outside any select. Once the buffer (poolCount = 3) is full and the fingerprint loop stops acquiring, Run blocks on that send forever: canceling the pool context and Close() do not unblock it, so every JARM-probed host leaks a goroutine.

Fix

  • Wait on a context-aware timer between dial failures instead of spinning.
  • Offer the connection with select on the pool context; on cancellation the dialed connection is removed from the in-flight set and closed.
  • Dial with net.Dialer.DialContext on the non-fastdialer path so a hung TCP connect honors cancellation.

Summary by CodeRabbit

  • Bug Fixes
    • Connection retries now pause briefly after failed attempts, reducing rapid repeated connection attempts.
    • Connection pool shutdown now responds to cancellation during retries and avoids retaining a connection when shutdown occurs before it can be queued. This helps ensure shutdown completes promptly, including when the pool is full, and prevents connections from remaining open unnecessarily.

hakarrr and others added 2 commits December 2, 2026 04:30
…down



Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The JARM one-time pool now uses a configurable dial function. It waits 100 ms after failed dials and stops retrying when its context is canceled. If cancellation occurs before a successful connection is enqueued, the pool removes and closes that connection.

Changes

JARM one-time connection pool

Layer / File(s) Summary
Dial retries and cancellation cleanup
common/hashes/jarm/onetimepool.go, common/hashes/jarm/onetimepool_test.go
The pool uses an overridable dial function and waits 100 ms between failed dials. It returns the context error if cancellation occurs during the wait or before enqueueing a successful connection. Tests check retry frequency and exit after pool closure.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: ice3man543

Merge Risk: Minimal · up to 359ed

This change stops the JARM connection pool from spinning on failed dials and from leaving a goroutine behind on shutdown. No remaining merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two main fixes in oneTimePool.Run: stopping the retry spin on dial failure and preventing a goroutine leak on shutdown. The raw summary shows backoff between dial retries, a contex…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two main fixes in oneTimePool.Run: stopping the retry spin on dial failure and preventing a goroutine leak on shutdown. The raw summary shows backoff between dial retries, a context-aware send with connection cleanup, and DialContext on the non-fastdialer path, all matching the title. The title is clear, specific, and under 80 characters.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit watches dials begin,
Then waits a beat before the next.
If context says the run must end,
The pool closes what it has kept.
Soft paws applaud the tidy exit.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 03beb0f6-8b93-49ad-96ef-ff2b4c0f892c
Commits

Reviewing files that changed from the base of the PR and between e8907f4 and 359edef.

Files selected for processing: 1

  • common/hashes/jarm/onetimepool_test.go
Files skipped from review as they are similar to previous changes: 1

  • common/hashes/jarm/onetimepool_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
@Mzack9999
Mzack9999 merged commit 1f08817 into projectdiscovery:dev Dec 2, 2026
13 checks passed
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.

2 participants