MotoreAdapter skips poll_ready, violating tower's Service contract for backpressure layers
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 64/100
Research direction
Start at motore::service::MotoreAdapter behind the tower feature and read the tower Service docs on cloning inner services. Reproduce with the issue's ConcurrencyLimit snippet, then change call so the exact cloned tower service it dispatches to has poll_ready awaited first (for example via oneshot or a poll_fn). Done means the snippet prints Ok(1) instead of panicking, with a regression test using a backpressure layer such as ConcurrencyLimit.
Written by the indexing model from the issue text.
Description
Bug Report
Version
motore 0.4.1 (crates.io; also present on main @ 4ffc9998 / 0.4.3)
motore-macros 0.4.1
tower 0.4.13 (features = ["limit", "util"])
Platform
Linux 6.12.113+deb13-amd64 x86_64
Crates
motore(tower feature)、tower(limit / util feature)。
Description
MotoreAdapter(tower Service 包装成 motore Service)clone tower 服务后直接 call,没有对 clone 出来的那个服务调用 poll_ready
tower 的 Service 要求在 call 之前 poll_ready 必须返回 Ready,否则实现方允许 panic:
"Before dispatching a request,
poll_readymust be called and returnPoll::Ready(Ok(())).""Implementations are permitted to panic if
callis invoked without obtainingPoll::Ready(Ok(()))frompoll_ready."
https://docs.rs/tower-service/0.3.3/tower_service/trait.Service.html
这段代码会出问题
use std::convert::Infallible;
use motore::service::MotoreAdapter;
use motore::Service as MotoreService;
use tower::limit::ConcurrencyLimit;
use tower::service_fn;
fn main() {
let tower_svc = ConcurrencyLimit::new(
service_fn(|req: u64| async move { Ok::<_, Infallible>(req) }),
1,
);
// tower::Service -> motore::Service
let motore_svc = tower_svc.motore(|_cx: &mut (), req: u64| req);
let mut cx = ();
let res = futures::executor::block_on(motore_svc.call(&mut cx, 1));
println!("{res:?}");
}
依赖:
motore = { version = "0.4.1", features = ["tower"] }
tower = { version = "0.4.13", features = ["limit", "util"] }
futures = "0.3"
期望看到:motore_svc.call 先对克隆出来的 tower 服务执行 poll_ready,然后 call,返回 Ok(1)。
实际看到:
thread 'main' panicked at tower-0.4.13/src/limit/concurrency/service.rs:87:14:
max requests in-flight; poll_ready must be called first
tower 的文档里有一段 "Be careful when cloning inner services" https://docs.rs/tower-service/latest/tower_service/trait.Service.html 说这种写法是 wrong and might panic 的。
fn call(&mut self, req: R) -> Self::Future {
let mut inner = self.inner.clone();
Box::pin(async move {
// `inner` might not be ready since its a clone
inner.call(req).await
})
}
刚好和 MotoreAdapter 的一模一样!
- Dominant language
- Rust
- Stars
- 282
- Forks
- 31
- Avg merge
- 3m
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cloudwego/motore
-
C-maintenance E-easy E-help-wanted T-good-first-issue
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
C-request E-help-wanted
Difficulty 1/5 Under an hour Newbie friendliness 15/100
All issues in cloudwego/motore
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
jelmer/buildlog-consultant#364 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
solutionscay/skiff#310 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
valkey-io/valkey-large-object#222 ·
Maintainers usually reply within 1 day
-
bug user-priority/P1
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day