timeout
Server-side timeout via tokio::time::timeout. Returns HTTP 504 if exceeded. Also forwarded to the
TypeScript client as the default timeout for that procedure. Works with both queries and
mutations.
Basic Usage
// 30 second server-side timeout
#[rpc_query(timeout = "30s")]
async fn slow_query() -> Report { ... }
// 5 second timeout on a mutation
#[rpc_mutation(timeout = "5s")]
async fn process_payment(input: PaymentInput) -> Receipt { ... }Duration Shorthand
#[rpc_query(timeout = "500ms")] // 500 milliseconds
#[rpc_query(timeout = "5s")] // 5 seconds
#[rpc_query(timeout = "1m")] // 1 minuteBehavior
When the handler exceeds the timeout, the future is cancelled and the server returns 504. The
TypeScript client receives an RpcError with
status 504.
// If the handler exceeds the timeout:
// 1. The future is cancelled via tokio::time::timeout
// 2. The server returns HTTP 504 Gateway Timeout
// 3. The TypeScript client receives an RpcError with status 504
#[rpc_query(timeout = "5s")]
async fn get_report() -> Report {
// If this takes > 5s, the client gets:
// RpcError { status: 504, message: "Gateway Timeout" }
expensive_computation().await
}Combining Attributes
// Combine with other attributes
#[rpc_query(cache = "1h", timeout = "5s", init = "setup")]
async fn fast_cached(db: &PgPool) -> Stats { ... }
#[rpc_mutation(timeout = "10s", idempotent)]
async fn upsert_record(input: RecordInput) -> Record { ... }Try it
Server-Side Timeout
This handler has a timeout = "3s" — it sleeps for the requested duration. Try a short
sleep to see a successful response, then try exceeding 3 seconds to trigger a 504.