Skip to content

fix(rqlite): validate rqlite node before first query#503

Open
doublesilver wants to merge 1 commit into
outerbase:developfrom
doublesilver:bounty/outerbase-studio-59
Open

fix(rqlite): validate rqlite node before first query#503
doublesilver wants to merge 1 commit into
outerbase:developfrom
doublesilver:bounty/outerbase-studio-59

Conversation

@doublesilver
Copy link
Copy Markdown

Changes

Before executing any SQL against an rqlite endpoint, perform a lightweight
probe: GET / on the configured host and check for the X-Rqlite-Version
response header. If the header is absent the server is not an rqlite node
and an informative error is raised immediately — before any query is sent.

How it works

  • RqliteQueryable gains a testConnection() async method that issues
    GET / with redirect: "manual" (so it works whether the server
    redirects to /status or not).
  • A connectionVerified flag ensures the check runs only once per
    instance; subsequent transaction() calls skip straight to the query.
  • On network failure the error message includes the configured endpoint
    to make debugging straightforward.

This follows the approach recommended in the issue by the rqlite
maintainer: call / and look for X-Rqlite-Version in the headers
(value irrelevant, presence is sufficient).

Testing

Unit tests added in src/drivers/database/rqlite.test.ts:

  • testConnection resolves when X-Rqlite-Version header is present
  • testConnection throws with a clear message when the header is absent
  • testConnection wraps network errors with the endpoint URL
  • transaction calls testConnection on the first invocation
  • transaction skips testConnection on subsequent invocations
  • transaction injects the Basic auth header when credentials are provided
  • transformRawResult maps columns/values and handles statement-only results

All 101 tests pass (npm test). TypeScript strict check clean (npm run tsc).

/claim #59

Before executing any SQL, call GET / on the configured endpoint and check
for the X-Rqlite-Version response header. If the header is missing the
endpoint is not an rqlite node and a clear error is thrown early.

The check runs once per RqliteQueryable instance (lazy on first
transaction) so repeated queries pay no extra overhead.

Adds unit tests covering successful validation, missing header, network
failure, lazy-init deduplication, and Basic auth header injection.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant