max / makenotwork
1 file changed,
+6 insertions,
-1 deletion
| @@ -400,7 +400,12 @@ pub async fn idempotency_middleware( | |||
| 400 | 400 | // cached response — subsequent requests should hit the DB and get | |
| 401 | 401 | // the cached body, not keep skipping via the stale negative. | |
| 402 | 402 | neg_cache.remove(&neg_key); | |
| 403 | - | tokio::spawn(async move { | |
| 403 | + | // Route through the bounded background pool, not a raw `tokio::spawn`: | |
| 404 | + | // this runs on every successful idempotent write, and an ungated | |
| 405 | + | // spawn would let a write burst accumulate tasks each grabbing a DB | |
| 406 | + | // pool connection — the exact contention `background.rs` exists to | |
| 407 | + | // bound (ultra-fuzz Run #1 Perf MODERATE). | |
| 408 | + | state.bg.spawn("idempotency_store", async move { | |
| 404 | 409 | if let Err(e) = crate::db::idempotency::store_response( | |
| 405 | 410 | &db, &key, user_id, &method, &path, status_code, &body_owned, | |
| 406 | 411 | ).await { |