{"record":{"id":"51638e0dc2e0df89","repo":"ArchiveBox/ArchiveBox","slug":"refusing-to-start-a-nested-supervisord-inherited","errorCode":null,"errorMessage":"Refusing to start a nested supervisord; inherited supervisor is unavailable at unix://{SOCK_FILE}","messagePattern":"Refusing to start a nested supervisord; inherited supervisor is unavailable at unix://(.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"archivebox/workers/supervisord_util.py","lineNumber":1008,"sourceCode":"    \"\"\"Poll for supervisord readiness without a fixed startup sleep.\"\"\"\n    deadline = time.monotonic() + max_wait_sec\n    supervisor = None\n    while time.monotonic() < deadline:\n        supervisor = get_existing_supervisord_process(quiet=quiet)\n        if supervisor is not None:\n            return supervisor\n        time.sleep(interval_sec)\n    return supervisor\n\n\ndef get_or_create_supervisord_process(daemonize=False):\n    SOCK_FILE = get_sock_file()\n    WORKERS_DIR = SOCK_FILE.parent / WORKERS_DIR_NAME\n\n    supervisor = get_existing_supervisord_process()\n    if supervisor is None:\n        if os.environ.get(\"SUPERVISOR_SERVER_URL\"):\n            raise RuntimeError(f\"Refusing to start a nested supervisord; inherited supervisor is unavailable at unix://{SOCK_FILE}\")\n        stop_existing_supervisord_process()\n        supervisor = start_new_supervisord_process(daemonize=daemonize)\n\n    if supervisor is None:\n        raise RuntimeError(\"Failed to start supervisord or connect to it\")\n    supervisor.getPID()  # make sure it doesn't throw an exception\n\n    (WORKERS_DIR / \"initial_startup.conf\").unlink(missing_ok=True)\n\n    return supervisor\n\n\ndef start_worker(supervisor, daemon, lazy=False):\n    existing = get_worker(supervisor, daemon[\"name\"])\n    if isinstance(existing, dict) and existing.get(\"statename\") in (\"STARTING\", \"RUNNING\"):\n        return existing\n    return sync_supervisord_workers(supervisor, [(daemon, lazy)], prune=False).get(daemon[\"name\"])\n","sourceCodeStart":990,"sourceCodeEnd":1026,"githubUrl":"https://github.com/ArchiveBox/ArchiveBox/blob/74564b28220090664f919479e82cbf454125fa34/archivebox/workers/supervisord_util.py#L990-L1026","documentation":"get_or_create_supervisord_process first tries get_existing_supervisord_process(). If none is reachable but SUPERVISOR_SERVER_URL is set in the environment, it means this process was spawned by a supervisord whose socket it can no longer connect to; it raises rather than starting a competing daemon.","triggerScenarios":"Calling get_or_create_supervisord_process (from ensure_daemon_stack, run_runner_worker, start_server_workers) in a process with SUPERVISOR_SERVER_URL set while the inherited supervisord is down, crashed, or its unix socket path is stale/mismatched.","commonSituations":"Parent supervisord restarted and socket file recreated with different path/hash; worker running in a container where the parent's socket isn't mounted; supervisord killed uncleanly leaving a dead socket; mismatched ARCHIVEBOX_WORKER_DIR between parent and child.","solutions":["Verify the socket path from SUPERVISOR_SERVER_URL exists and is connectable; restart the parent supervisord so the socket is recreated","Point SUPERVISOR_SERVER_URL / ArchiveBox worker dir config to the correct, matching socket path","Remove stale socket files in the workers dir and restart the daemon stack from a top-level command (`archivebox server`)","Unset SUPERVISOR_SERVER_URL only if this process is truly standalone and should own a fresh supervisord"],"exampleFix":"// before: inherited URL points at dead socket\nSUPERVISOR_SERVER_URL=unix:///old/hash/supervisor.sock archivebox run\n// after\nls data/workers/*.sock  # find current socket\nexport SUPERVISOR_SERVER_URL=unix://<current>/supervisor.sock\narchivebox run","handlingStrategy":"validation","validationCode":"import os, socket\nurl = os.environ.get('SUPERVISOR_SERVER_URL', '')\nif url.startswith('unix://'):\n    sock = url[len('unix://'):]\n    if not os.path.exists(sock):\n        # inherited supervisor socket is gone; fix env or restart the daemon stack first\n        raise SystemExit(f'SUPERVISOR_SERVER_URL points at missing socket: {sock}')\n    s = socket.socket(socket.AF_UNIX); s.connect(sock); s.close()","typeGuard":null,"tryCatchPattern":"try:\n    supervisor = get_or_create_supervisord_process()\nexcept RuntimeError as e:\n    if 'inherited supervisor is unavailable' in str(e):\n        print('parent supervisord socket dead; restarting daemon stack from top level')\n        os.environ.pop('SUPERVISOR_SERVER_URL', None)\n        supervisor = get_or_create_supervisord_process()\n    else:\n        raise","preventionTips":["Mount the parent supervisord socket into containers that set SUPERVISOR_SERVER_URL","Keep the ArchiveBox worker dir path identical for parent and child processes","Restart the whole daemon stack together so sockets and env stay in sync","Clean up stale unix sockets after unclean shutdowns"],"tags":["supervisord","socket","environment","daemon"],"backgroundTag":"daemon-socket-unreachable","analyzedSha":"74564b28220090664f919479e82cbf454125fa34","analyzedAt":"2026-08-28T23:56:51.556Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}