Skip to content

Bug: Daemon crashes with "Cannot send a request, as the client has been closed" on index and search #173

@Abeldewit

Description

@Abeldewit

Daemon crashes with "Cannot send a request, as the client has been closed"

Environment

  • OS: Ubuntu 24
  • Python: 3.13.1 (via pyenv)
  • cocoindex-code: 0.2.33
  • SQLite: 3.51.2

Symptoms

Both ccc index and ccc search consistently fail with the same httpx client lifecycle error:

RuntimeError: Cannot send a request, as the client has been closed.

The daemon appears healthy (shows uptime and loaded projects), but all operations fail immediately.

Reproduction

Step 1: Environment Setup

pyenv shell 3.13.1
python3 -c "import sqlite3; conn = sqlite3.connect(':memory:'); conn.enable_load_extension(True); print('✓ OK')"

Step 2: Install cocoindex-code

rm -rf ~/.local/pipx
pipx install --python /path/to/python3.13.1/bin/python 'cocoindex-code[full]'

Step 3: Initialize Project

cd /path/to/large/monorepo
ccc init

Step 4: Attempt Indexing

ccc index

Result:

Project: /path/to/large/monorepo
Indexing failed: Cannot send a request, as the client has been closed.

Step 5: Check Daemon Status

ccc daemon status

Result: Daemon shows healthy (uptime: 4593.9s, projects loaded)

Step 6: Attempt Search

ccc search "query"

Result:

RuntimeError: Daemon error: Cannot send a request, as the client has been closed.

Step 7: Restart Daemon

ccc daemon restart
ccc index

Result: Still fails with same error

Step 8: Kill and Force Restart

pkill -9 -f "ccc.*daemon"
sleep 2
ccc index

Result: Still fails with same error

Step 9: Run Doctor Command

ccc doctor

Key findings:

[FAIL] Model Check (indexing)
  ERROR: RuntimeError: Cannot send a request, as the client has been closed.

[FAIL] Model Check (query)
  ERROR: RuntimeError: Cannot send a request, as the client has been closed.

[FAIL] Index Status
  Index: /path/to/large/monorepo/.cocoindex_code/target_sqlite.db
  ERROR: no such table: code_chunks_vec

The SQLite database exists but critical tables never initialized.

Analysis

The error comes from httpx's client state management:

if self._state == ClientState.CLOSED:
    raise RuntimeError("Cannot send a request, as the client has been closed.")

This suggests:

  1. The daemon's httpx client is being closed prematurely
  2. Either during embedding model initialization or between requests
  3. The daemon attempts to reuse a closed client

Similar Issues

Both involved improper httpx client lifecycle management in daemon contexts.

What Works

  • ✅ Python 3.13.1 has SQLite extension support
  • ✅ Daemon process starts and stays running
  • ✅ File discovery works (226 files detected)
  • ccc doctor can analyze the project

What Fails

  • ccc index crashes immediately
  • ccc search crashes immediately
  • ❌ Database initialization incomplete
  • ❌ Restart/kill/retry have no effect
  • ❌ Systematic failure, not transient

Attempts Made

Approach Result
Clean pipx installation Still fails
Daemon restart Still fails
Full daemon kill and restart Still fails
Fresh project init Still fails

Expected vs Actual

Expected:

  • ccc index creates tables and indexes files
  • ccc search returns semantic results
  • Daemon maintains persistent httpx session

Actual:

  • All operations fail with closed client error
  • Database left in broken state
  • Daemon appears healthy but non-functional

Questions for Maintainers

  1. How is httpx client lifecycle managed in the daemon?
  2. Is the client reused or created per-request?
  3. Is the embedding model loader closing the session?
  4. Is there a TTL or timeout that closes active sessions?
  5. Why does ccc doctor detect files but indexing fails?

System Details

python3 --version
# Python 3.13.1

python3 -c "import sqlite3; print(sqlite3.sqlite_version)"
# 3.51.2

ccc doctor
# Shows: embedding provider=sentence-transformers, model=Snowflake/snowflake-arctic-embed-xs
# Shows: version 0.2.33, project with 226 files

Next Steps

I'm willing to:

  • Enable debug logging if available
  • Test on different Python versions
  • Try earlier versions (0.1.x)
  • Provide daemon logs for analysis
  • Test with a minimal reproduction repo

Please advise on debugging steps or if this is a known issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions