fix(rqlite): validate rqlite node before first query#503
Open
doublesilver wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Before executing any SQL against an rqlite endpoint, perform a lightweight
probe:
GET /on the configured host and check for theX-Rqlite-Versionresponse 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
RqliteQueryablegains atestConnection()async method that issuesGET /withredirect: "manual"(so it works whether the serverredirects to
/statusor not).connectionVerifiedflag ensures the check runs only once perinstance; subsequent
transaction()calls skip straight to the query.to make debugging straightforward.
This follows the approach recommended in the issue by the rqlite
maintainer: call
/and look forX-Rqlite-Versionin the headers(value irrelevant, presence is sufficient).
Testing
Unit tests added in
src/drivers/database/rqlite.test.ts:testConnectionresolves whenX-Rqlite-Versionheader is presenttestConnectionthrows with a clear message when the header is absenttestConnectionwraps network errors with the endpoint URLtransactioncallstestConnectionon the first invocationtransactionskipstestConnectionon subsequent invocationstransactioninjects the Basic auth header when credentials are providedtransformRawResultmaps columns/values and handles statement-only resultsAll 101 tests pass (
npm test). TypeScript strict check clean (npm run tsc)./claim #59