# Command Timeout (/sdks/rust/how-to/rpc/command-timeout)



## Overview [#overview]

A **command timeout** is the deadline you attach to a single RPC call so a caller never blocks forever waiting on a handler that isn't there or isn't responding. Commands are synchronous by design — the sender is parked until a reply arrives — so without a bound, a missing subscriber or a crashed handler turns one request into an indefinite hang that ties up a task and cascades into upstream timeouts.

The timeout is set per call with `.timeout(Duration)` on `CommandBuilder`, and it's enforced by the broker itself, not by client-side polling: the broker tracks the deadline server-side and fails the request the moment it expires, regardless of what the calling task is doing. When the window elapses with no response, `send_command` returns `Err(KubemqError::Timeout)`, a variant that reports `is_retryable()` as true — your signal to retry or fall back.

**Gotchas:** a command timeout is a broker-enforced deadline, not a Tokio task cancellation, so don't assume cancelling the calling task also stops the broker from waiting; a slow-but-alive handler and a completely absent one produce the *same* `Timeout` error, so you can't tell them apart from the error alone; and setting the timeout too short under normal load turns transient latency into false failures — size it against real handler processing time, not the 5-second default.

## Prerequisites [#prerequisites]

* KubeMQ server running on `localhost:50000`
* Rust SDK installed (`cargo add kubemq`)

## Code [#code]

```rust title="main.rs"
use kubemq::prelude::*;
use kubemq::CommandBuilder;
use std::time::Duration;

#[tokio::main]
async fn main() -> kubemq::Result<()> {
    let client = KubemqClient::builder()
        .host("localhost")
        .port(50000)
        .build()
        .await?;

    let command = CommandBuilder::new()
        .channel("rust-rpc.command-timeout")
        .body(b"will-timeout".to_vec())
        .timeout(Duration::from_secs(3))
        .build();

    match client.send_command(command).await {
        Ok(resp) => println!("Executed: {}", resp.executed),
        Err(e) if e.is_retryable() => println!("Timeout (retryable): {}", e),
        Err(e) => println!("Error: {}", e),
    }

    client.close().await?;
    Ok(())
}
```

## How It Works [#how-it-works]

* The `timeout` field sets the maximum wait time for a response (default: 5 seconds).
* If no subscriber responds in time, a `KubemqError::Timeout` is returned (retryable).
* Use `e.is_retryable()` to distinguish timeout from permanent failures.
* Review timeouts, channel names, and client IDs before running against shared environments.
* Run the program while the server from the prerequisites is available.

## Related [#related]

* [RPC overview](/learn/rpc)
* [Rust SDK Reference](/sdks/rust/reference/rpc)
* [Command Send](/sdks/rust/tutorials/command-send)
