Fix fake-async crawler and socket leaks in dirrec/portscan (proper async + context managers) - #82
Open
Matt2454 wants to merge 1 commit into
Open
Fix fake-async crawler and socket leaks in dirrec/portscan (proper async + context managers)#82Matt2454 wants to merge 1 commit into
Matt2454 wants to merge 1 commit into
Conversation
…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.
|
Hello |
Author
|
hello..? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This patch addresses three architectural flaws in FinalRecon's async/concurrency
code that caused high overhead and leaked sockets:
modules/crawler.py): was "async in name only" — it wrappedblocking
requestscalls inasyncio.to_thread+ nestedThreadPoolExecutor,spawning/borrowing a thread per request and defeating the
threading.localsession cache. Replaced with a single shared
aiohttp.ClientSession(managedvia
async with) and bounded concurrency through anasyncio.Semaphore.modules/dirrec.py): manually created and immediately closed a newevent loop, cutting off aiohttp's background socket-cleanup. Now uses
asyncio.run()for correct loop/session lifecycle, with worker tasks torn downin a
finallyblock so the session/connector always close.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()contextmanager that always closes the writer, and
run()awaits worker cancellation.Changes
modules/crawler.py: shared async session, bounded semaphore, removedrequests/ThreadPoolExecutor/threading-local machinery.modules/dirrec.py:asyncio.run()+try/finallyworker teardown.modules/portscan.py:open_streamasync context manager, awaitedcancellation, fixed
queue.task_done()accounting.Testing
py_compilepasses for all three modules.portscanverified against localhost (detected open ports, clean teardown).crawlerverified end-to-end against a local HTTP server (robots, sitemap,css, js, images extracted over the shared async session).