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
Result:
Project: /path/to/large/monorepo
Indexing failed: Cannot send a request, as the client has been closed.
Step 5: Check Daemon Status
Result: Daemon shows healthy (uptime: 4593.9s, projects loaded)
Step 6: Attempt Search
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
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:
- The daemon's httpx client is being closed prematurely
- Either during embedding model initialization or between requests
- 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
- How is httpx client lifecycle managed in the daemon?
- Is the client reused or created per-request?
- Is the embedding model loader closing the session?
- Is there a TTL or timeout that closes active sessions?
- 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:
Please advise on debugging steps or if this is a known issue.
Daemon crashes with "Cannot send a request, as the client has been closed"
Environment
Symptoms
Both
ccc indexandccc searchconsistently fail with the same httpx client lifecycle error: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
Step 3: Initialize Project
cd /path/to/large/monorepo ccc initStep 4: Attempt Indexing
Result:
Step 5: Check Daemon Status
Result: Daemon shows healthy (uptime: 4593.9s, projects loaded)
Step 6: Attempt Search
ccc search "query"Result:
Step 7: Restart Daemon
Result: Still fails with same error
Step 8: Kill and Force Restart
pkill -9 -f "ccc.*daemon" sleep 2 ccc indexResult: Still fails with same error
Step 9: Run Doctor Command
Key findings:
The SQLite database exists but critical tables never initialized.
Analysis
The error comes from httpx's client state management:
This suggests:
Similar Issues
Both involved improper httpx client lifecycle management in daemon contexts.
What Works
ccc doctorcan analyze the projectWhat Fails
ccc indexcrashes immediatelyccc searchcrashes immediatelyAttempts Made
Expected vs Actual
Expected:
ccc indexcreates tables and indexes filesccc searchreturns semantic resultsActual:
Questions for Maintainers
ccc doctordetect files but indexing fails?System Details
Next Steps
I'm willing to:
Please advise on debugging steps or if this is a known issue.