Skip to content

Fix fake-async crawler and socket leaks in dirrec/portscan (proper async + context managers) - #82

Open
Matt2454 wants to merge 1 commit into
thewhiteh4t:masterfrom
Matt2454:master
Open

Fix fake-async crawler and socket leaks in dirrec/portscan (proper async + context managers)#82
Matt2454 wants to merge 1 commit into
thewhiteh4t:masterfrom
Matt2454:master

Conversation

@Matt2454

Copy link
Copy Markdown

Summary

This patch addresses three architectural flaws in FinalRecon's async/concurrency
code that caused high overhead and leaked sockets:

  • crawler (modules/crawler.py): was "async in name only" — it wrapped
    blocking requests calls in asyncio.to_thread + nested ThreadPoolExecutor,
    spawning/borrowing a thread per request and defeating the threading.local
    session cache. Replaced with a single shared aiohttp.ClientSession (managed
    via async with) and bounded concurrency through an asyncio.Semaphore.
  • dirrec (modules/dirrec.py): manually created and immediately closed a new
    event loop, cutting off aiohttp's background socket-cleanup. Now uses
    asyncio.run() for correct loop/session lifecycle, with worker tasks torn down
    in a finally block so the session/connector always close.
  • portscan (modules/portscan.py): raw sockets could be left open ("zombie"
    connections) on error/cancellation, and worker tasks were cancelled without
    awaiting. Sockets are now wrapped in an async with open_stream() context
    manager that always closes the writer, and run() awaits worker cancellation.

Changes

  • modules/crawler.py: shared async session, bounded semaphore, removed
    requests/ThreadPoolExecutor/threading-local machinery.
  • modules/dirrec.py: asyncio.run() + try/finally worker teardown.
  • modules/portscan.py: open_stream async context manager, awaited
    cancellation, fixed queue.task_done() accounting.

Testing

  • py_compile passes for all three modules.
  • portscan verified against localhost (detected open ports, clean teardown).
  • crawler verified end-to-end against a local HTTP server (robots, sitemap,
    css, js, images extracted over the shared async session).

…tscan

Convert crawler to a shared async aiohttp session (no per-request threads),
use asyncio.run() for proper aiohttp session/connector cleanup in dirrec, and
wrap raw sockets in an async with context manager with awaited cancellation in
portscan to prevent zombie connections.
@aaddjjk

aaddjjk commented Aug 13, 2026

Copy link
Copy Markdown

Hello

@Matt2454

Copy link
Copy Markdown
Author

hello..?

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