Skip to content

serve and CLI commands cannot coexist — KuzuDB file lock prevents concurrent access #325

@ShunsukeHayashi

Description

@ShunsukeHayashi

Environment

  • GitNexus version: 1.4.1 (Homebrew / npm global)
  • Node.js version: v25.6.1
  • OS: macOS (Darwin 25.2.0, ARM64)

Bug

When gitnexus serve is running (e.g. for the Web UI on port 4747), all CLI commands that access the KuzuDB database fail with a file lock error. This includes cypher, context, impact, query, and analyze.

Reproduction

# Terminal 1: Start server
gitnexus serve --port 4747

# Terminal 2: Try any CLI command
gitnexus cypher --repo MY_REPO "MATCH (c:Community) RETURN c.label LIMIT 1" 2>&1
# Error: IO exception: Could not set lock on file : /path/to/.gitnexus/kuzu
# See the docs: https://docs.kuzudb.com/concurrency for more information.

The same error occurs for context, query, impact, status, and analyze --force.

Expected behavior

Ideally, the serve process and CLI commands should be able to share read access to the database. KuzuDB supports concurrent read connections, so this may be solvable by using shared/read-only connections for CLI queries when the server holds the write lock.

Alternatively, the CLI could detect the lock and print a helpful message like:

Error: Database is locked by gitnexus serve (PID 12345).
Run `lsof -ti :4747 | xargs kill` to stop the server first.

Workaround

Kill the server before running CLI commands:

lsof -ti :4747 | xargs kill 2>/dev/null
sleep 2
gitnexus cypher --repo MY_REPO "..."

Impact

This is especially painful when:

  1. The Web UI is being used for visual exploration while CLI is needed for scripting
  2. The MCP server (gitnexus mcp) is running and CLI commands are attempted in parallel
  3. Automated scripts (cron reindex, graph-meta updates) run while the server is active

Related issues: #285, #290 (concurrent query crashes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions