Skip to content

Concurrent WebSocket startup can race creating ProjectContext #14

@rsolmano

Description

@rsolmano

Description

Concurrent WebSocket connections for the same project can both create and start a ProjectContext before either one stores it in _projects. When both contexts initialize the same SQLite spec index at the same time, one can fail with sqlite3.OperationalError: database is locked.

Steps to reproduce

  1. Start two WebSocket clients for the same fresh project at nearly the same time.
  2. Have both clients call RPC methods, such as spec/list.
  3. This showed up in CI in tests/rpc/test_server.py::TestMultiClientIntegration::test_two_clients_both_can_call_rpc.

Expected behavior

Only one ProjectContext.start() should run per project, and concurrent clients should share the same initialized context.

Actual behavior

The second concurrent startup can try to initialize the same SQLite index and fail:

sqlite3.OperationalError: database is locked
app/rpc/server.py:310: await new_ctx.start()
app/rpc/project_context.py:236: needs_rebuild = await self.index.open_and_check(...)
app/spec/index.py:227: await self._conn.execute(line)

Environment

  • OS: GitHub Actions Ubuntu runner; local macOS repeated runs did not reproduce
  • Python version (python --version): Python 3.11.15 in the failing CI run
  • Node version (node --version): N/A
  • ThinkRail version / commit: observed while checking PR Generate schemas before Vite startup #8 at 71096ac200c1f240a6e63127a179bca9ecd352d4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    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