Repository navigation
fix(pnpr): bound libsql auth backend reads with a timeout - #12645
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds timeout enforcement for libsql auth startup and read operations, stores a per-backend auth timeout, and broadens shared SQLx error gating for libsql builds. Adds tests for timeout success and expiry. ChangesLibsql auth timeout handling
Sequence Diagram(s)sequenceDiagram
participant LibsqlAuth
participant with_auth_timeout
participant tokio_time_timeout
LibsqlAuth->>with_auth_timeout: wrap startup or read future
with_auth_timeout->>tokio_time_timeout: enforce duration
tokio_time_timeout-->>with_auth_timeout: value or timeout
with_auth_timeout-->>LibsqlAuth: result or AuthDatabaseTimeout
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related PRs
Suggested labels
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoBound libsql/Turso auth reads with tokio timeouts (surface 504 on stall) Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1. Startup build lacks timeout
|
| /// Deadline for the one-time startup connect + schema setup. More generous | ||
| /// than [`DEFAULT_AUTH_TIMEOUT`] (cold schema DDL against a remote primary can | ||
| /// be slow) but still bounded so an unreachable database fails fast. | ||
| const DEFAULT_STARTUP_TIMEOUT: Duration = Duration::from_mins(5); | ||
|
|
There was a problem hiding this comment.
3. Startup build lacks timeout 🐞 Bug ☼ Reliability
LibsqlAuth::connect still awaits Builder::build().await without any deadline, so a stalled/blackholed libsql endpoint can hang pnpr startup indefinitely even though the PR introduces DEFAULT_STARTUP_TIMEOUT for “startup connect + schema setup”. This undermines the intended bounded startup failure behavior and can block restarts/rollouts under network partitions or hostile endpoints.
Agent Prompt
## Issue description
`LibsqlAuth::connect` still performs `builder.build().await?` without a timeout. Even after adding `DEFAULT_STARTUP_TIMEOUT` and wrapping `init_schema`, startup can still hang indefinitely while creating the `Database` (remote connect / initial sync), which defeats the stated goal of bounding startup failure.
## Issue Context
The sqlx backend wraps both startup connect and startup schema setup in `with_auth_timeout(settings.startup_timeout, ...)`. The libsql backend should mirror this by applying `DEFAULT_STARTUP_TIMEOUT` (or a future config knob) around `Builder::build()` as well.
## Fix Focus Areas
- pnpr/crates/pnpr/src/auth/libsql_backend.rs[111-127]
- pnpr/crates/pnpr/src/auth/libsql_backend.rs[51-75]
## Expected change
Wrap both `Builder::new_remote_replica(...).build()` and `Builder::new_remote(...).build()` in `with_auth_timeout(DEFAULT_STARTUP_TIMEOUT, ...)` so startup cannot hang indefinitely on database creation.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Code review by qodo was updated up to the latest commit 6bd255a |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12645 +/- ##
==========================================
- Coverage 88.72% 88.71% -0.02%
==========================================
Files 342 342
Lines 50341 50393 +52
==========================================
+ Hits 44663 44704 +41
- Misses 5678 5689 +11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Integrated-Benchmark Report (Linux)Commit: Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.76494954246,
"stddev": 0.174107483376719,
"median": 4.690031983960001,
"user": 3.92291798,
"system": 3.4260922400000005,
"min": 4.62412614496,
"max": 5.19035288496,
"times": [
4.67877407096,
4.63944324996,
5.19035288496,
4.87530600996,
4.6799447369600005,
4.76335913596,
4.86022638096,
4.63784357896,
4.70011923096,
4.62412614496
]
},
{
"command": "pacquet@main",
"mean": 4.61975506936,
"stddev": 0.09815071540922704,
"median": 4.5919099154600005,
"user": 3.858616279999999,
"system": 3.4132455399999997,
"min": 4.52467647596,
"max": 4.81824156496,
"times": [
4.81824156496,
4.70415627196,
4.59475645196,
4.72569174396,
4.52936586496,
4.58906337896,
4.52467647596,
4.52846114996,
4.58020058396,
4.60293720696
]
},
{
"command": "pnpr@HEAD",
"mean": 3.03334543406,
"stddev": 0.11537524498188478,
"median": 3.01598103296,
"user": 2.850984779999999,
"system": 3.00950314,
"min": 2.85839867996,
"max": 3.21735255896,
"times": [
3.15484343296,
2.94498660896,
3.02481568796,
3.21735255896,
3.06955966296,
3.15794575996,
2.9717101239600003,
2.92669544696,
3.00714637796,
2.85839867996
]
},
{
"command": "pnpr@main",
"mean": 3.0802449896599997,
"stddev": 0.1122416977806664,
"median": 3.08419864096,
"user": 2.8265410799999993,
"system": 2.9977298399999994,
"min": 2.87625523196,
"max": 3.21707376496,
"times": [
3.00191590596,
3.21707376496,
3.21216246996,
3.01555995796,
2.87625523196,
3.18582481796,
3.13236250396,
3.04058710696,
2.9928979619600002,
3.12781017496
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.6661620120800001,
"stddev": 0.011247657474878714,
"median": 0.66629462538,
"user": 0.39522794,
"system": 1.3589209599999996,
"min": 0.6519065228800001,
"max": 0.68665315788,
"times": [
0.65730957388,
0.67262755088,
0.66633397488,
0.65230172888,
0.66625527588,
0.67965183188,
0.66162704188,
0.68665315788,
0.66695346188,
0.6519065228800001
]
},
{
"command": "pacquet@main",
"mean": 0.7010200801800001,
"stddev": 0.07300926782467239,
"median": 0.68156136638,
"user": 0.40507934,
"system": 1.3494001599999998,
"min": 0.64884775788,
"max": 0.89957585488,
"times": [
0.70842788188,
0.64884775788,
0.6682489338800001,
0.65638463288,
0.6770682678800001,
0.69259298488,
0.65989789288,
0.68605446488,
0.89957585488,
0.71310212988
]
},
{
"command": "pnpr@HEAD",
"mean": 0.7468846388799999,
"stddev": 0.06994094860555247,
"median": 0.72559146988,
"user": 0.40856493999999993,
"system": 1.3862586599999998,
"min": 0.6971292558800001,
"max": 0.93638027788,
"times": [
0.74512408488,
0.71537111988,
0.6971292558800001,
0.71937060188,
0.7105404308800001,
0.73181233788,
0.93638027788,
0.75443798388,
0.7582145358800001,
0.70046575988
]
},
{
"command": "pnpr@main",
"mean": 0.7426993267800002,
"stddev": 0.05597877698568244,
"median": 0.73021428588,
"user": 0.40872274,
"system": 1.38600766,
"min": 0.69945145588,
"max": 0.89767294988,
"times": [
0.7447096228800001,
0.7302457598800001,
0.72561804488,
0.69945145588,
0.70903093588,
0.7319508408800001,
0.73018281188,
0.72247050288,
0.89767294988,
0.73566034288
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.933072570539999,
"stddev": 0.025202289246051238,
"median": 4.93637563094,
"user": 4.006467379999999,
"system": 3.409645059999999,
"min": 4.89260087194,
"max": 4.97302453294,
"times": [
4.92997318594,
4.90613432694,
4.92373049394,
4.9470030849399995,
4.97302453294,
4.94277807594,
4.95758875494,
4.9097579399399995,
4.94813443794,
4.89260087194
]
},
{
"command": "pacquet@main",
"mean": 4.951284499039999,
"stddev": 0.05253339071423558,
"median": 4.95430161444,
"user": 4.00188688,
"system": 3.40659176,
"min": 4.86996206094,
"max": 5.02537882594,
"times": [
4.98151093394,
5.02537882594,
4.91153438594,
4.88280331394,
5.02173807394,
4.94642126894,
4.86996206094,
4.94139570894,
4.9699184579399995,
4.96218195994
]
},
{
"command": "pnpr@HEAD",
"mean": 3.331371114739999,
"stddev": 0.13013208281772717,
"median": 3.28237660744,
"user": 2.91743708,
"system": 3.21577376,
"min": 3.1941000539399997,
"max": 3.57862933094,
"times": [
3.57862933094,
3.2600336199399997,
3.19688991094,
3.41374612594,
3.51058538194,
3.1941000539399997,
3.2731077159399997,
3.29164549894,
3.25822745694,
3.33674605194
]
},
{
"command": "pnpr@main",
"mean": 3.3584371984399994,
"stddev": 0.11237954829582242,
"median": 3.37761725294,
"user": 2.93128238,
"system": 3.1980211599999997,
"min": 3.20592908094,
"max": 3.52175163194,
"times": [
3.47277484594,
3.33739189694,
3.2500564809399997,
3.20592908094,
3.44660529594,
3.42380011994,
3.52175163194,
3.41784260894,
3.27784291994,
3.23037710294
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.4715768210800002,
"stddev": 0.01494393420244026,
"median": 1.47538700818,
"user": 1.4276041000000002,
"system": 1.7720040999999997,
"min": 1.4389762291800001,
"max": 1.48887397718,
"times": [
1.45842115118,
1.4743755971799999,
1.48793242418,
1.46494216318,
1.4389762291800001,
1.4763984191800001,
1.48887397718,
1.47920220618,
1.46749299818,
1.47915304518
]
},
{
"command": "pacquet@main",
"mean": 1.4842432544800002,
"stddev": 0.03593729234023176,
"median": 1.4813457571800002,
"user": 1.4404784000000004,
"system": 1.7732291999999998,
"min": 1.43322365818,
"max": 1.54584427118,
"times": [
1.54584427118,
1.47317384818,
1.53097401418,
1.50377278518,
1.48951766618,
1.47075454018,
1.4930351961800001,
1.4460784151800001,
1.45605815018,
1.43322365818
]
},
{
"command": "pnpr@HEAD",
"mean": 1.51927847958,
"stddev": 0.02103590315886905,
"median": 1.5164120566800001,
"user": 0.6090048000000001,
"system": 1.6019444999999997,
"min": 1.48379112618,
"max": 1.55447945418,
"times": [
1.53351154718,
1.5174830941800002,
1.50657758018,
1.53179272618,
1.49755731918,
1.48379112618,
1.5398972561800002,
1.55447945418,
1.51235367318,
1.51534101918
]
},
{
"command": "pnpr@main",
"mean": 1.51411517398,
"stddev": 0.017374969009024195,
"median": 1.50712248718,
"user": 0.5912331,
"system": 1.6145133999999999,
"min": 1.49749506018,
"max": 1.54013650518,
"times": [
1.53659606518,
1.5033005401800001,
1.54013650518,
1.51007347518,
1.5108870191800001,
1.49924262618,
1.50417149918,
1.53877898918,
1.50046996018,
1.49749506018
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 3.2093676777800004,
"stddev": 0.03128966674063475,
"median": 3.2061243110800004,
"user": 1.8905392799999998,
"system": 2.04688178,
"min": 3.16791140108,
"max": 3.28304088508,
"times": [
3.2299312180800004,
3.21045347508,
3.21873986908,
3.18502085308,
3.16791140108,
3.1922233290800004,
3.2036214280800004,
3.28304088508,
3.1941071250800004,
3.2086271940800004
]
},
{
"command": "pacquet@main",
"mean": 3.22951517098,
"stddev": 0.058214253247579714,
"median": 3.22239002208,
"user": 1.8978529800000001,
"system": 2.0370574799999996,
"min": 3.16488538408,
"max": 3.38277540308,
"times": [
3.19969322108,
3.2163106950800002,
3.16488538408,
3.22922844708,
3.2426053980800003,
3.2213927620800002,
3.38277540308,
3.1912998380800004,
3.22357327908,
3.22338728208
]
},
{
"command": "pnpr@HEAD",
"mean": 1.5093009170800002,
"stddev": 0.02889628144306855,
"median": 1.51236830658,
"user": 0.5996594799999999,
"system": 1.5994675799999998,
"min": 1.46477836408,
"max": 1.5507187850800002,
"times": [
1.5251397530800002,
1.48864438808,
1.5423715680799999,
1.5507187850800002,
1.48407743908,
1.52202378508,
1.48191777308,
1.50271282808,
1.53062448708,
1.46477836408
]
},
{
"command": "pnpr@main",
"mean": 1.5190700184800003,
"stddev": 0.032102359581574307,
"median": 1.52569980808,
"user": 0.60444498,
"system": 1.6038243799999996,
"min": 1.46916259508,
"max": 1.57009651908,
"times": [
1.53593581008,
1.57009651908,
1.52066516708,
1.54589638208,
1.5376588260800002,
1.53073444908,
1.51559136508,
1.46916259508,
1.4836009000800001,
1.48135817108
]
}
]
} |
|
| Branch | pr/12645 |
| Testbed | pacquet |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result milliseconds (ms) (Result Δ%) | Upper Boundary milliseconds (ms) (Limit %) |
|---|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 4,933.07 ms(+3.48%)Baseline: 4,767.28 ms | 5,720.74 ms (86.23%) |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot 🚷 view threshold | 3,209.37 ms(+5.53%)Baseline: 3,041.08 ms | 3,649.30 ms (87.94%) |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 1,471.58 ms(+9.09%)Baseline: 1,348.95 ms | 1,618.74 ms (90.91%) |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 4,764.95 ms(+1.97%)Baseline: 4,672.86 ms | 5,607.43 ms (84.98%) |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 666.16 ms(+6.14%)Baseline: 627.61 ms | 753.14 ms (88.45%) |
|
| Branch | pr/12645 |
| Testbed | pnpr |
⚠️ WARNING: No Threshold found!Without a Threshold, no Alerts will ever be generated.
Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the--ci-only-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 3,331.37 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 1,509.30 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 1,519.28 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 3,033.35 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 746.88 ms |
|
Code review by qodo was updated up to the latest commit 28aad49 |
1 similar comment
|
Code review by qodo was updated up to the latest commit 28aad49 |
|
Thanks @qodo — dispositions:
Written by an agent (Claude Code, claude-opus-4-8). |
Thanks — that all makes sense.
So the main security-relevant change here is the bounded timeout on request-path reads, which looks appropriately targeted. |
Every request-path database call in the libsql/Turso auth backend was a bare await with no timeout, while the sqlx backend wraps its reads in with_auth_timeout and returns AuthDatabaseTimeout (HTTP 504). A stalled or hostile libsql endpoint could hold a Tokio task open indefinitely on every authenticated request, exhausting the executor and taking the whole registry down — a remote DoS with no 504 ever returned. Wrap the request-path reads (stored_hash, user_count, lookup, find_by_key, list_for_user) and the startup schema setup with a deadline, surfacing AuthDatabaseTimeout on expiry. The AuthDatabaseTimeout variant and its log_kind / status_code arms now compile under backend-libsql, not just the sqlx drivers. Writes stay unwrapped for the reason the sqlx backend documents: a cancelled write would leave an unknown commit state. The read deadline uses a 30s default to match the sqlx backend; exposing it as a YAML knob is a follow-up. with_auth_timeout mirrors the sqlx helper, kept separate because the two backends are independently feature-gated. Co-authored-by: Claude <[email protected]>
CI Rust Doc runs with default features, where the sqlx_backend module is not compiled, so the [`super::sqlx_backend`] intra-doc link was unresolvable (broken-intra-doc-links). The Perfectionist dylint also rejects single-letter generics. Use a plain code span for the cross-module reference and rename the generics to Loaded/DbError. Co-authored-by: Claude <[email protected]>
28aad49 to
658bf8e
Compare
|
Code review by qodo was updated up to the latest commit 658bf8e |
1 similar comment
|
Code review by qodo was updated up to the latest commit 658bf8e |
…lper Wrap both Builder::build() paths (remote replica and remote) in with_auth_timeout(DEFAULT_STARTUP_TIMEOUT, ...) so a stalled or blackholed libsql endpoint cannot hang pnpr startup indefinitely, matching the bounded-startup behavior the sqlx backend already has. The build futures are Box::pin'd so the one-time startup connect does not enlarge the serve future past the large_futures threshold. Deduplicate with_auth_timeout: move it into the shared auth module so both the libsql and sqlx backends use one helper instead of two copies. Its doc no longer claims libsql writes rely on a statement timeout (libsql configures none); it states the real invariant that writes must await directly to avoid an unknown commit state. Trim the timeout constant doc comments to a contract-focused line each, dropping the DoS narrative and PR-history references.
|
Code review by qodo was updated up to the latest commit ab07d06 |
1 similar comment
|
Code review by qodo was updated up to the latest commit ab07d06 |
Summary
Every request-path database call in the libsql/Turso auth backend (
stored_hash,user_count,lookup,find_by_key,list_for_user) was a bare.await?with no timeout. The sqlx backend,by contrast, wraps each read in
with_auth_timeoutand surfacesAuthDatabaseTimeout(HTTP 504)on expiry. A stalled or hostile libsql endpoint (network partition, overloaded primary,
slow-loris) could therefore hold a Tokio task open indefinitely on every authenticated request,
exhausting the executor and taking the whole registry down — a remote DoS, with no 504 ever
returned.
This wraps the request-path reads and the startup schema setup with a deadline. The
AuthDatabaseTimeoutvariant (and itslog_kind/status_codearms) now compiles underbackend-libsql, not just the sqlx drivers. Writes are intentionally left unwrapped, for the samereason the sqlx backend documents: a Tokio cancellation mid-write would leave an unknown commit
state, so writes rely on the database's own statement timeout.
The read deadline uses a 30s default to match the sqlx backend. Exposing it as a YAML knob
(
backend.libsql.timeout, like the sqlx backends) is a follow-up; this PR fixes the unboundedhang.
with_auth_timeoutmirrors the sqlx helper rather than sharing it, because the two backendsare independently feature-gated.
Squash Commit Body
Checklist
fast result passes through).
LibsqlAuthholds a concretelibsql::Connectionrather than aninjectable trait, so a connection-level stall isn't reproducible in a unit test the way the
sqlx backend's
SlowLookupBackendis; the helper test plus the wrapped call sites cover it.(No changeset: pnpr is not a published npm package. No pnpm-side port: pnpr-only infrastructure.)
Written by an agent (Claude Code, claude-opus-4-8).
Summary by CodeRabbit