← LeaderboardThe Skill Leaderboard
rust-tower-service-readiness
Repair Tower middleware that polls one Rust service handle and calls a clone. Keep readiness, backpressure reservations, and calls on the same service instance.
Try your first task
A source-grounded starter task has not been verified for this skill yet.
SKILL.md
name: rust-tower-service-readinessdescription: Repair Tower middleware that polls one Rust service handle and calls a clone. Keep readiness, backpressure reservations, and calls on the same service instance.category: developmentrisk: criticalsource: selfsource_type: selfdate_added: "2026-12-02"author: ShianMiketags: [rust, tower, middleware, async, backpressure]Rust Tower Service Readiness
When to Use
- Tower middleware calls an inner service that panics because
poll_readywas never called on that instance. - A service stalls after a wrapper moves a cloned inner handle into an async future.
- A call needs to preserve a queue slot or concurrency permit reserved during readiness.
Prerequisites
- The Tower service implementation, resolved crate version, and any capacity-limiting layers.
- The normal request entry point and the handle polled before dispatch.
- A local capacity-limited service to test readiness and backpressure.
1. Trace readiness to the dispatched call
- Identify the exact inner service value polled by the wrapper's
poll_ready. Check whethercalloperates on that value. - Inspect clones made to store state in async futures. Even when handles share an underlying semaphore or queue, a clone can start without the original handle's reservation.
- Follow the service's
Poll::Pendingand error paths. A pending service must be repolled after wakeup. Handle a readiness error before dispatch. - Use a capacity-limiting inner service when reproducing. An always-ready test service can hide the mismatch.
2. Keep the prepared instance
- When possible, call the ready inner service synchronously inside the wrapper's
calland move the returned future into the async block. - When the async block needs the ready service value itself, clone a replacement for the wrapper and use
std::mem::replaceto move the original ready value into the block. - When a fresh handle owns the whole operation, use
ServiceExt::oneshotor awaitready()and call the same handle. Check for a reservation still held by another handle before awaiting readiness. - Keep backpressure and error handling consistent with the existing layer. Verify how reservations are released if a prepared service or its returned future is dropped.
3. Verify the capacity boundary
- Reproduce a call made on an unprepared clone independently from the corrected path.
- Check that another handle is pending while all capacity is reserved. Then dispatch with the ready instance and assert its actual response.
- Send another request after completion to verify the replacement handle can acquire capacity.
- Add a targeted readiness failure or cancellation case when the middleware changes behavior in those paths.
Example
Run Call the ready handle. A real Tower ConcurrencyLimit exposes the unprepared clone and verifies that transferring the ready handle preserves its reservation.
Limitations
- The fixture uses one Tokio thread, a one-permit service, and in-memory requests. Real service scheduling, timeouts, retries, and request cancellation need their own checks.
- A service can reserve a different resource or none. Inspect the service contract before assuming that a particular layer holds a permit.
Safety and Side Effects
- Run the example in a scratch Cargo project. It uses synthetic requests and local build artifacts.
- Middleware changes can alter request admission and cancellation. Validate with a disposable service before applying them to a production route.
Related Skills and Documentation
- Axum development for in-process route tests.
- Rust async patterns
- Tower Service readiness and cloning
- Tower ServiceExt::oneshot
- Tower ConcurrencyLimit