This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
backendcritical PriorityID: axum-08-tower-http3-multiplex-drain

Axum 0.8 / HTTP/3 Zero-Drop Graceful Shutdown and Multiplexed Drain Guardrail

Enforces deterministic two-phase GOAWAY signaling, QUIC connection draining states, and synchronized Tower service pipeline completion in Axum 0.8 deployments. Guarantees zero dropped client requests and boundary-safe stream abortion during rolling container orchestrations over HTTP/3.

Prohibited Anti-Pattern: Uncoordinated QUIC Endpoint Dropping Leading to Abrupt Stream Truncation and Rolling Deploy 502/504 Errors

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Axum 0.8 / HTTP/3 Zero-Drop Graceful Shutdown and Multiplexed Drain Guardrail - Enforces deterministic two-phase GOAWAY signaling, QUIC connection draining states, and synchronized Tower service pipeline completion in Axum 0.8 deployments. Guarantees zero dropped client requests and boundary-safe stream abortion during rolling container orchestrations over HTTP/3.
globs: src/**/*.rs
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/axum-08-tower-http3-multiplex-drain"
---

# Axum 0.8 / HTTP/3 Zero-Drop Graceful Shutdown and Multiplexed Drain Guardrail

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: Uncoordinated QUIC Endpoint Dropping Leading to Abrupt Stream Truncation and Rolling Deploy 502/504 Errors

## System Constraints
You are a Principal Systems Architect enforcing mission-critical HTTP/3 and QUIC transport invariants in Rust (Axum 0.8, Tower, Hyper/h3, Quinn/s2n-quic). In HTTP/3 rolling orchestrations, dropping the UDP socket or abruptly terminating the runtime immediately aborts active multiplexed bidirectional streams with CONNECTION_CLOSE or transport-level resets. You must mandate a strict two-phase graceful drain: (1) stop accepting new QUIC connections, (2) transmit appropriate HTTP/3 GOAWAY frames with the negotiated stream ID ceiling, (3) permit in-flight requests to complete against Tower layers up to a bounded orchestration grace timeout, and (4) ensure transport migration safety during the drain window.

## Strict Guidelines
- Engineers MUST ALWAYS separate the QUIC accept loop termination from the multiplexed stream drain phase using cooperative cancellation tokens (`tokio_util::sync::CancellationToken`).
- Engineers MUST ALWAYS issue an HTTP/3 `GOAWAY` frame with stream ID bounds prior to closing underlying QUIC connections, preventing edge-proxy 502/504 storms.
- Engineers MUST NOT drop the `quinn::Endpoint` or `s2n_quic::Server` handle directly in a `tokio::select!` block upon receiving `SIGTERM` or `SIGINT`.
- Services MUST track in-flight Tower request executions using `tokio_util::task::TaskTracker` or an explicit concurrent stream barrier.
- Engineers MUST enforce a bounded drain timeout that aligns with orchestration termination grace periods (e.g., Kubernetes `terminationGracePeriodSeconds` minus a safety buffer).
- Components NEVER abort active bidirectional QUIC streams without sending transport-level `H3_NO_ERROR` (0x0100) or application-level error codes if the hard drain ceiling is exceeded.

## Bad vs Good Implementations
### HTTP/3 & QUIC Transport Graceful Drain Implementation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Dropping the HTTP/3 driver or QUIC endpoint immediately upon receiving an OS signal causes active multiplexed streams to terminate abruptly without emitting GOAWAY frames or completing in-flight Tower service pipelines, inducing packet resets and 502/504 errors on clients.
```rust
use axum::{routing::get, Router};
use tokio::net::UdpSocket;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = Router::new().route("/", get(|| async { "Hello, HTTP/3!" }));
    
    // ANTI-PATTERN: Direct select drop terminates active QUIC streams immediately
    tokio::select! {
        _ = run_http3_server(app) => {},
        _ = tokio::signal::ctrl_c() => {
            // Quinn/h3 endpoint is dropped immediately.
            // Active multiplexed streams receive immediate CONNECTION_CLOSE (transport error)
            // Clients experience silent drops and 502 Bad Gateway during pod rolling restarts.
            println!("Received SIGINT, terminating process immediately.");
        }
    }
    Ok(())
}

async fn run_http3_server(_router: Router) {
    // Hypothetical raw h3/quinn server loop
}
```

#### Production Standard (Correct)
> **Standard**: Implements an orchestration-safe cancellation pipeline using CancellationToken and TaskTracker. Signals incoming connection rejection while broadcasting GOAWAY frames and allowing active multiplexed streams to drain up to a bounded timeout.
```rust
use axum::{routing::get, Router};
use std::time::Duration;
use tokio::signal::unix::{signal, SignalKind};
use tokio_util::sync::CancellationToken;
use tokio_util::task::TaskTracker;

const DRAIN_TIMEOUT: Duration = Duration::from_secs(25);

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let cancel_token = CancellationToken::new();
    let tracker = TaskTracker::new();
    
    let app = Router::new().route("/", get(|| async { "Hello, Zero-Drop HTTP/3!" }));

    // Spawn signal listener for clean orchestrator handoff
    let shutdown_signal = cancel_token.clone();
    tokio::spawn(async move {
        let mut sigterm = signal(SignalKind::terminate()).expect("Failed to bind SIGTERM");
        tokio::select! {
            _ = tokio::signal::ctrl_c() => {},
            _ = sigterm.recv() => {},
        }
        shutdown_signal.cancel();
    });

    // Run HTTP/3 server with coordinated drain
    run_http3_server_with_drain(app, cancel_token.clone(), tracker.clone()).await?;

    // Wait for in-flight requests up to bounded orchestration deadline
    tokio::select! {
        _ = tracker.wait() => {
            tracing::info!("All multiplexed HTTP/3 streams drained cleanly.");
        }
        _ = tokio::time::sleep(DRAIN_TIMEOUT) => {
            tracing::warn!("Drain timeout expired; forcing QUIC endpoint shutdown.");
        }
    }

    Ok(())
}

async fn run_http3_server_with_drain(
    _router: Router,
    cancel_token: CancellationToken,
    tracker: TaskTracker,
) -> Result<(), Box<dyn std::error::Error>> {
    // 1. Accept connections until cancel_token is fired.
    // 2. On cancellation: close the QUIC endpoint to reject new connections.
    // 3. Emit HTTP/3 GOAWAY with current stream bounds across active connections.
    // 4. Drive tracker.track_future(...) on active stream requests.
    tracker.close();
    Ok(())
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Axum 0.8 / HTTP/3 Zero-Drop Graceful Shutdown and Multiplexed Drain Guardrail

Axum 0.8 / HTTP/3 Zero-Drop Graceful Shutdown and Multiplexed Drain Guardrail defines an industrial-grade behavioral standard for backend engineering. Enforces deterministic two-phase GOAWAY signaling, QUIC connection draining states, and synchronized Tower service pipeline completion in Axum 0.8 deployments. Guarantees zero dropped client requests and boundary-safe stream abortion during rolling container orchestrations over HTTP/3. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Uncoordinated QUIC Endpoint Dropping Leading to Abrupt Stream Truncation and Rolling Deploy 502/504 Errors Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftUncoordinated QUIC Endpoint Dropping Leading to Abrupt Stream Truncation and Rolling Deploy 502/504 ErrorsCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS separate the QUIC accept loop termination from the multiplexed stream drain phase using cooperative cancellation tokens (`tokio_util

Engineers MUST ALWAYS separate the QUIC accept loop termination from the multiplexed stream drain phase using cooperative cancellation tokens (`tokio_util::sync::CancellationToken`).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST ALWAYS issue an HTTP/3 `GOAWAY` frame with stream ID bounds prior to closing underlying QUIC connections, preventing edge-proxy 502/504 storms.

Engineers MUST ALWAYS issue an HTTP/3 `GOAWAY` frame with stream ID bounds prior to closing underlying QUIC connections, preventing edge-proxy 502/504 storms.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST NOT drop the `quinn

Engineers MUST NOT drop the `quinn::Endpoint` or `s2n_quic::Server` handle directly in a `tokio::select!` block upon receiving `SIGTERM` or `SIGINT`.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Services MUST track in-flight Tower request executions using `tokio_util

Services MUST track in-flight Tower request executions using `tokio_util::task::TaskTracker` or an explicit concurrent stream barrier.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Engineers MUST enforce a bounded drain timeout that aligns with orchestration termination grace periods (e.g., Kubernetes `terminationGracePeriodSeconds` minus a safety buffer).

Engineers MUST enforce a bounded drain timeout that aligns with orchestration termination grace periods (e.g., Kubernetes `terminationGracePeriodSeconds` minus a safety buffer).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

Components NEVER abort active bidirectional QUIC streams without sending transport-level `H3_NO_ERROR` (0x0100) or application-level error codes if the hard drain ceiling is exceeded.

Components NEVER abort active bidirectional QUIC streams without sending transport-level `H3_NO_ERROR` (0x0100) or application-level error codes if the hard drain ceiling is exceeded.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Axum 0.8 / HTTP/3 Zero-Drop Graceful Shutdown and Multiplexed Drain Guardrail critical for AI coding assistants?

Enforces deterministic two-phase GOAWAY signaling, QUIC connection draining states, and synchronized Tower service pipeline completion in Axum 0.8 deployments. Guarantees zero dropped client requests and boundary-safe stream abortion during rolling container orchestrations over HTTP/3. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Uncoordinated QUIC Endpoint Dropping Leading to Abrupt Stream Truncation and Rolling Deploy 502/504 Errors) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Axum