Skip to content

perf: search index rebuild is not atomic and drops tables on concurrent requests #122

Open

Description

@rohilsurana

Problem

src/server/api/search.ts drops and recreates FTS tables in buildIndex() on each version init. If two requests hit the search endpoint simultaneously during index build, the second request can fail because the tables were just dropped.

The lock file mechanism (/tmp/chronicle-search-ready) is also unreliable across processes and deployments since temp files get cleaned.

Suggested Fix

  • Build the new index in temporary tables, then atomically swap (rename) them
  • Replace the lock file with an in-memory ready flag (already have indexedVersions set — lean on that)
  • Add a mutex/promise guard so concurrent ensureIndex() calls wait for the first build to complete (partially done via indexPromise but the drop/recreate pattern still races)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions