AI powered OSINT engine to discover and map 840+ social media identities across the web
Python aiartificial-intelligencedebainhackhackerhackinghackingtoolsinformationinformation-gatheringlinuxlinux-desktoposintpythonpython-scriptpython3social-mediasocialmediahackingtermuxtermux-tool
fix: the browser fallback launched many Chromiums and leaked pages (#26); release 2.7.2
arxhr0077d8b79c22cde
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex df3ad9e..191747c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,5 +1,27 @@# Changelog+## 2.7.2 (2026-10-19)++### Fixed+- **The browser fallback could start dozens of Chromium processes and keep pages open+ forever** (#26, a Mac that ran out of memory with the fallback switched on). The fallback+ (`--playwright`, or "fallback" in the interactive settings) re-checks every "Maybe" result+ in a real browser. Two bugs in it:+ - The browser was started on first use, and the check for "already started" ran before the+ lock that guards it. With 50 scan workers asking at once, each one launched its own+ Chromium, and only the last was ever closed.+ - A page that timed out, failed to load, or was cancelled by the scan's deadline was never+ closed, so a scan accumulated hundreds of open pages.++ The browser now starts once, every page is closed whatever happens, the browser context is+ replaced every 40 pages so its memory is returned, and a browser that fails halfway through+ starting is shut down. Checked against a real Chromium: 20 simultaneous fetches, half to a+ page that never finishes loading, now use one browser (4 processes), 341 MB at most, and+ leave no page open and no process running after the scan. The old code, given only 8+ simultaneous fetches, passed 1.5 GB in seconds.++ Scans without the fallback were never affected.+## 2.7.1 (2026-10-19)### Addeddiff --git a/pyproject.toml b/pyproject.tomlindex ac63bb6..3368b42 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "hatchling.build"[project]name = "aliens-eye"-version = "2.7.1"+version = "2.7.2"description = "AI-powered OSINT username scanner across 800+ social media and web platforms"readme = "README.md"requires-python = ">=3.10"diff --git a/src/aliens_eye/__init__.py b/src/aliens_eye/__init__.pyindex 9f6f78a..e9613f6 100644--- a/src/aliens_eye/__init__.py+++ b/src/aliens_eye/__init__.py@@ -1,3 +1,3 @@"""Aliens Eye - AI-powered OSINT username scanner."""-__version__ = "2.7.1"+__version__ = "2.7.2"diff --git a/src/aliens_eye/core/browser.py b/src/aliens_eye/core/browser.pyindex aa87445..7d75ebd 100644--- a/src/aliens_eye/core/browser.py+++ b/src/aliens_eye/core/browser.py@@ -1,8 +1,16 @@import asyncio+# A browser holds on to memory for every page it has ever rendered, closed or not.+# Replacing its context now and then hands that memory back to the system.+RECYCLE_AFTER_PAGES = 40+CLOSE_TIMEOUT = 5.0+class BrowserFallback:- """Playwright-based fallback for hard pages."""+ """Playwright-based fallback for hard pages.++ Starts one browser, on first use, and shows it one page at a time.+ """def __init__(self, timeout: float, user_agent: str) -> None:self.timeout = timeout@@ -10,6 +18,7 @@ class BrowserFallback:self._playwright = Noneself._browser = Noneself._context = None+ self._pages_in_context = 0self._lock = asyncio.Lock()async def start(self) -> None:@@ -19,25 +28,57 @@ class BrowserFallback:raise RuntimeError("Playwright is not installed") from excself._playwright = await async_playwright().start()- self._browser = await self._playwright.chromium.launch(headless=True)- self._context = await self._browser.new_context(user_agent=self.user_agent)+ try:+ self._browser = await self._playwright.chromium.launch(headless=True)+ self._context = await self._browser.new_context(user_agent=self.user_agent)+ except BaseException:+ await self.close() # never leave a half-started browser running+ raise+ self._pages_in_context = 0async def close(self) -> None:- if self._context:- await self._context.close()- if self._browser:- await self._browser.close()- if self._playwright:- await self._playwright.stop()+ context, browser, playwright = self._context, self._browser, self._playwright+ self._context = self._browser = self._playwright = None+ self._pages_in_context = 0+ for closer in (context and context.close, browser and browser.close,+ playwright and playwright.stop):+ if closer is None:+ continue+ try:+ await asyncio.wait_for(closer(), CLOSE_TIMEOUT)+ except Exception: # noqa: BLE001 - shutting down; there is nothing left to save+ pass- async def fetch(self, url: str) -> tuple[str, str]:- if not self._context:+ async def _fresh_context(self):+ """The context to open the next page in, replaced every so many pages."""+ if self._context is None:await self.start()+ elif self._pages_in_context >= RECYCLE_AFTER_PAGES:+ old = self._context+ self._context = await self._browser.new_context(user_agent=self.user_agent)+ self._pages_in_context = 0+ try:+ await asyncio.wait_for(old.close(), CLOSE_TIMEOUT)+ except Exception: # noqa: BLE001+ pass+ return self._context+ async def fetch(self, url: str) -> tuple[str, str]:+ # Starting the browser is inside the lock: with 50 scan workers asking at+ # once, checking first and starting outside it launched one Chromium each.async with self._lock:- page = await self._context.new_page()- await page.goto(url, wait_until="domcontentloaded", timeout=int(self.timeout * 1000))- content = await page.content()- final_url = page.url- await page.close()+ context = await self._fresh_context()+ page = await context.new_page()+ self._pages_in_context += 1+ try:+ await page.goto(url, wait_until="domcontentloaded", timeout=int(self.timeout * 1000))+ content = await page.content()+ final_url = page.url+ finally:+ # Also on a timeout, an error, or a cancelled scan: an open page+ # stays in the browser, and a scan has hundreds of these to load.+ try:+ await asyncio.wait_for(page.close(), CLOSE_TIMEOUT)+ except Exception: # noqa: BLE001+ passreturn content, final_urldiff --git a/tests/test_browser.py b/tests/test_browser.pynew file mode 100644index 0000000..00bd488--- /dev/null+++ b/tests/test_browser.py@@ -0,0 +1,201 @@+"""The Playwright fallback must not leak browsers or pages (#26).++A scan that reported 40+ GB of memory on a laptop had the fallback switched on.+Chromium is the likely holder: every "Maybe" result opens a page, and a scan has+hundreds. These tests use a fake Playwright, so they need no browser.+"""++import asyncio+import sys+import types++import pytest++from aliens_eye.core.browser import BrowserFallback+++class FakePage:+ def __init__(self, world, fail=None, hang=False):+ self.world, self.fail, self.hang = world, fail, hang+ self.url = "https://example.test/final"+ self.closed = False++ async def goto(self, url, **kwargs):+ self.world.open_pages.add(self)+ self.world.peak_open = max(self.world.peak_open, len(self.world.open_pages))+ if self.hang:+ await asyncio.sleep(3600)+ if self.fail:+ raise self.fail+ await asyncio.sleep(0.01)++ async def content(self):+ return "<html>ok</html>"++ async def close(self):+ self.closed = True+ self.world.open_pages.discard(self)+++class FakeContext:+ def __init__(self, world):+ self.world, self.closed = world, False++ async def new_page(self):+ self.world.pages_created += 1+ mode = self.world.next_page_mode()+ page = FakePage(self.world, **mode)+ self.world.all_pages.append(page)+ return page++ async def close(self):+ self.closed = True+ # Closing a context closes its pages.+ for page in list(self.world.open_pages):+ page.closed = True+ self.world.open_pages.discard(page)+++class FakeBrowser:+ def __init__(self, world):+ self.world, self.closed = world, False++ async def new_context(self, **kwargs):+ context = FakeContext(self.world)+ self.world.contexts.append(context)+ return context++ async def close(self):+ self.closed = True+++class FakeChromium:+ def __init__(self, world):+ self.world = world++ async def launch(self, **kwargs):+ await asyncio.sleep(0.05) # starting a real browser takes a while+ browser = FakeBrowser(self.world)+ self.world.browsers.append(browser)+ return browser+++class FakePlaywright:+ def __init__(self, world):+ self.chromium = FakeChromium(world)++ async def stop(self):+ pass+++class World:+ def __init__(self):+ self.browsers, self.contexts, self.all_pages = [], [], []+ self.open_pages, self.peak_open, self.pages_created = set(), 0, 0+ self.modes = []++ def next_page_mode(self):+ return self.modes.pop(0) if self.modes else {}+++def world(monkeypatch):+ world = World()++ class Starter:+ async def start(self):+ await asyncio.sleep(0.05)+ return FakePlaywright(world)++ module = types.ModuleType("playwright.async_api")+ module.async_playwright = lambda: Starter()+ package = types.ModuleType("playwright")+ package.async_api = module+ monkeypatch.setitem(sys.modules, "playwright", package)+ monkeypatch.setitem(sys.modules, "playwright.async_api", module)+ return world+++async def test_concurrent_first_fetches_start_one_browser(world):+ """Regression: 50 workers hitting a Maybe together each launched a Chromium."""+ fallback = BrowserFallback(timeout=5, user_agent="test")+ await asyncio.gather(*(fallback.fetch(f"https://example.test/{i}") for i in range(30)))+ assert len(world.browsers) == 1+ assert len(world.contexts) == 1+ await fallback.close()+ assert world.browsers[0].closed+++async def test_a_page_that_fails_to_load_is_still_closed(world):+ world.modes = [{"fail": RuntimeError("net::ERR_TIMED_OUT")}]+ fallback = BrowserFallback(timeout=5, user_agent="test")+ with pytest.raises(RuntimeError):+ await fallback.fetch("https://example.test/a")+ assert world.all_pages[0].closed+ assert world.open_pages == set()+++async def test_a_cancelled_fetch_closes_its_page(world):+ """The scan gives each site a deadline and cancels it; the page must not outlive that."""+ world.modes = [{"hang": True}]+ fallback = BrowserFallback(timeout=5, user_agent="test")+ task = asyncio.create_task(fallback.fetch("https://example.test/slow"))+ await asyncio.sleep(0.3)+ task.cancel()+ with pytest.raises(asyncio.CancelledError):+ await task+ assert world.all_pages[0].closed+ assert world.open_pages == set()+++async def test_one_page_is_open_at_a_time(world):+ fallback = BrowserFallback(timeout=5, user_agent="test")+ await asyncio.gather(*(fallback.fetch(f"https://example.test/{i}") for i in range(20)))+ assert world.peak_open == 1+++async def test_the_context_is_recycled_so_browser_memory_stays_bounded(world, monkeypatch):+ monkeypatch.setattr("aliens_eye.core.browser.RECYCLE_AFTER_PAGES", 5)+ fallback = BrowserFallback(timeout=5, user_agent="test")+ for i in range(12):+ await fallback.fetch(f"https://example.test/{i}")+ assert len(world.browsers) == 1 # the browser is reused+ assert len(world.contexts) == 3 # 12 pages at 5 per context+ assert [c.closed for c in world.contexts] == [True, True, False]+ await fallback.close()+ assert all(c.closed for c in world.contexts)+++async def test_a_failed_close_does_not_hide_the_result(world, monkeypatch):+ fallback = BrowserFallback(timeout=5, user_agent="test")++ async def broken_close(self):+ raise RuntimeError("target closed")++ monkeypatch.setattr(FakePage, "close", broken_close)+ content, final_url = await fallback.fetch("https://example.test/a")+ assert content == "<html>ok</html>" and final_url == "https://example.test/final"+++async def test_close_is_safe_when_never_started(world):+ await BrowserFallback(timeout=5, user_agent="test").close()+++async def test_fetch_after_close_starts_fresh(world):+ fallback = BrowserFallback(timeout=5, user_agent="test")+ await fallback.fetch("https://example.test/a")+ await fallback.close()+ await fallback.fetch("https://example.test/b")+ assert len(world.browsers) == 2+++async def test_a_browser_that_fails_halfway_through_starting_is_shut_down(world, monkeypatch):+ """The browser launched, the context did not: the browser must not be left running."""+ async def broken_context(self, **kwargs):+ raise RuntimeError("could not create a context")++ monkeypatch.setattr(FakeBrowser, "new_context", broken_context)+ fallback = BrowserFallback(timeout=5, user_agent="test")+ with pytest.raises(RuntimeError):+ await fallback.fetch("https://example.test/a")+ assert len(world.browsers) == 1 and world.browsers[0].closed