这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 19, 2025

Problem

The "Install All Packages" button would fail on fresh installs (where no python/ venv directory exists yet) with a "Session is closed" error. This error would be repeatedly spammed in the terminal, preventing any packages from being installed. The package download spinners would spin forever with no actual progress.

Workaround: Installing a single package first (e.g., "Install PyTorch") would work, and then "Install All Packages" would work on subsequent attempts.

Root Cause

When installing dependencies, the worker process is stopped and restarted (to avoid conflicts during pip installation). The sequence is:

  1. worker.stop() - closes the aiohttp session
  2. Install dependencies via pip
  3. worker.start() - creates a new session

However, the stop() method was closing the session but not setting self._session = None. This created a race condition:

  • Frontend continuously polls /installed-dependencies endpoint during installation
  • The endpoint calls worker.get_packages() which calls wait_for_ready()
  • wait_for_ready() checks if self._session is not None - this returns True even though the session is closed
  • Code attempts to use the closed session → RuntimeError: Session is closed

Solution

Modified WorkerServer.stop() to properly nullify resources after closing them:

async def stop(self):
    if self._process:
        self._process.close()
        self._process = None  # Added
    if self._session:
        for resp in self._manually_close:
            resp.close()
        self._manually_close.clear()
        await self._session.close()
        self._session = None  # Added
    self._is_ready = False  # Added
    logger.info("Worker process stopped")

Now wait_for_ready() will properly wait for the worker to be restarted (and a new session created) before allowing any requests to proceed.

Testing

  • ✅ Python linter passes (ruff)
  • ✅ All existing tests pass
  • ✅ CodeQL security analysis - no vulnerabilities found

Fixes the issue described where "Install All Packages" fails on fresh installs.

Original prompt

This section details on the original issue you should resolve

<issue_title>"Install All Packages" button breaks due to error with http://127.0.0.1:8000/installed-dependencies</issue_title>
<issue_description>Information:

  • Chainner version: 0f85bed
  • OS: Linux x64

Description
This happens on completely fresh installs (where there's no python/ venv dir yet).

The "Install All Packages" button breaks due to attempting to connect to http://127.0.0.1:8000/installed-dependencies, which errors with "Session is closed". This error is repeatedly spammed forever in the terminal.

As a result, nothing is being installed. The package download spinners spin forever, and no download progress is happening in the terminal or GUI.

Workaround

Clicking on a single package and installing just ONE package works properly, such as clicking on "Install PyTorch".

And after successfully installing a single package, THEN the "Install All Packages" button starts working too.

Logs

06:07:40.830 › Backend: [149326] [ERROR] Error installing dependencies: An error occurred while installing dependencies.
Traceback (most recent call last):
  File "chaiNNer-linux-x64/resources/src/server_host.py", line 315, in install_dependencies_request
    await install_dependencies(deps, progress, logger)
  File "chaiNNer-linux-x64/resources/src/dependencies/store.py", line 234, in install_dependencies
    raise ValueError("An error occurred while installing dependencies.")
ValueError: An error occurred while installing dependencies.
06:07:40.833 › Backend: [2024-12-06 06:07:40 +0100] [149326] [ERROR] Exception occurred while handling uri: 'http://127.0.0.1:8000/installed-dependencies'
Traceback (most recent call last):
  File "handle_request", line 97, in handle_request
    from sanic_ext.extensions.base import Extension  # type: ignore
                       ^^^^^^^^^^^^^^
  File "chaiNNer-linux-x64/resources/src/server_host.py", line 194, in get_installed_dependencies
    packages = await worker.get_packages()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "chaiNNer-linux-x64/resources/src/server_process_helper.py", line 269, in get_packages
    async with self._session.get(
  File "chaiNNer-linux-x64/python/python/lib/python3.11/site-packages/aiohttp/client.py", line 1194, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "chaiNNer-linux-x64/python/python/lib/python3.11/site-packages/aiohttp/client.py", line 425, in _request
    raise RuntimeError("Session is closed")
RuntimeError: Session is closed
06:07:40.839 › Error: The application encountered an unexpected error and could not continue.
    at kP.fromJson (file://chaiNNer-linux-x64/resources/app/.vite/renderer/main_window/index.js:398:4951)
    at Ine.fetchJson (file://chaiNNer-linux-x64/resources/app/.vite/renderer/main_window/index.js:398:5629)
    at async Object.queryFn (file://chaiNNer-linux-x64/resources/app/.vite/renderer/main_window/index.js:828:1396)
06:07:41.840 › Backend: [2024-12-06 06:07:41 +0100] [149326] [ERROR] Exception occurred while handling uri: 'http://127.0.0.1:8000/installed-dependencies'
Traceback (most recent call last):
  File "handle_request", line 97, in handle_request
    from sanic_ext.extensions.base import Extension  # type: ignore
                       ^^^^^^^^^^^^^^
  File "chaiNNer-linux-x64/resources/src/server_host.py", line 194, in get_installed_dependencies
    packages = await worker.get_packages()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "chaiNNer-linux-x64/resources/src/server_process_helper.py", line 269, in get_packages
    async with self._session.get(
  File "chaiNNer-linux-x64/python/python/lib/python3.11/site-packages/aiohttp/client.py", line 1194, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "chaiNNer-linux-x64/python/python/lib/python3.11/site-packages/aiohttp/client.py", line 425, in _request
    raise RuntimeError("Session is closed")
RuntimeError: Session is closed
06:07:41.841 › Error: The application encountered an unexpected error and could not continue.
    at kP.fromJson (file://chaiNNer-linux-x64/resources/app/.vite/renderer/main_window/index.js:398:4951)
    at Ine.fetchJson (file://chaiNNer-linux-x64/resources/app/.vite/renderer/main_window/index.js:398:5629)
    at async Object.queryFn (file://chaiNNer-linux-x64/resources/app/.vite/renderer/main_window/index.js:828:1396)
06:07:43.843 › Backend: [2024-12-06 06:07:43 +0100] [149326] [ERROR] Exception occurred while handling uri: 'http://127.0.0.1:8000/installed-dependencies'
Traceback (most recent call last):
  File "handle_request", line 97, in handle_request
    from sanic_ext.extensions.base import Extension  # type: ignore
                       ^^^^^^^^^^^^^^
  File "chaiNNer-linux-x64/resou...

</details>

Fixes chaiNNer-org/chaiNNer#3056

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

Copilot AI changed the title [WIP] Fix error with install all packages button Fix "Session is closed" error during package installation Oct 19, 2025
Copilot finished work on behalf of joeyballentine October 19, 2025 05:47
Copilot AI requested a review from joeyballentine October 19, 2025 05:47
Copilot AI and others added 2 commits October 19, 2025 14:47
Co-authored-by: joeyballentine <34788790+joeyballentine@users.noreply.github.com>
@joeyballentine joeyballentine force-pushed the copilot/fix-install-all-packages-error branch from 32baef4 to d839170 Compare October 19, 2025 19:48
@joeyballentine joeyballentine force-pushed the main branch 2 times, most recently from d0e4684 to 5007ca9 Compare October 22, 2025 21:07
@joeyballentine
Copy link
Member

I need to actually test this to see if this is a good change or not. I don't trust it

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