CodeSampleX

샘플

tower 0.4.13: Poll CallAll stream without hanging in an infinite loop when the request stream yields Pending

검증된 샘플 — cargo tower 0.4.13: Poll CallAll stream without hanging in an infinite loop when the request stream yields Pending. rust 1 · linux alpine/x64 …

sha256:fa35534865f2db9d70805f04058ceeef34da6469bb812a6d45a7d4bada79a112

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
3
빌드한 서명 키
3
선언된 환경 rust linux x64 rust rust cargo

검증 실행 환경

환경 컨트랙트 단계 실행일
rust 1 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1
2026-08-17
rust 1 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1
2026-08-18
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-09-08

케이스

HOW
목표
Poll CallAll stream without hanging in an infinite loop when the request stream yields Pending
패키지
심벌
  • tower::ServiceExt::call_all
  • tower::util::CallAll
환경
rust
생성일
2026-08-17T02:35:44Z

컨트랙트

  1. let mut call_all = svc.call_all(futures_util::stream::pending::<&'static str>());
  2. let poll_result = Pin::new(&mut call_all).poll_next(&mut cx);
  3. assert!(poll_result.is_pending());

파일

  • .gitignore
  • Cargo.lock
  • Cargo.toml
  • NOTES.md
  • csx.json
  • src/lib.rs

소스 아티팩트 내려받기 (tar.gz)

소스

.gitignore
/target
Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "futures-core"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"

[[package]]
name = "futures-macro"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44"
dependencies = [
 "proc-macro2",
 "quote",
 "syn 3.0.3",
]

[[package]]
name = "futures-task"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd"

[[package]]
name = "futures-util"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
dependencies = [
 "futures-core",
 "futures-macro",
 "futures-task",
 "pin-project-lite",
 "slab",
]

[[package]]
name = "log"
version = "0.4.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"

[[package]]
name = "once_cell"
version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"

[[package]]
name = "pin-project"
version = "1.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2466b2336ed02bcdca6b294417127b90ec92038d1d5c4fbeac971a922e0e0924"
dependencies = [
 "pin-project-internal",
]

[[package]]
name = "pin-project-internal"
version = "1.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b"
dependencies = [
 "proc-macro2",
 "quote",
 "syn 2.0.119",
]

[[package]]
name = "pin-project-lite"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"

[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
 "unicode-ident",
]

[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
 "proc-macro2",
]

[[package]]
name = "slab"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"

[[package]]
name = "syn"
version = "2.0.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-ident",
]

[[package]]
name = "syn"
version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-ident",
]

[[package]]
name = "tower"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c"
dependencies = [
 "futures-core",
 "futures-util",
 "pin-project",
 "pin-project-lite",
 "tower-layer",
 "tower-service",
 "tracing",
]

[[package]]
name = "tower-layer"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"

[[package]]
name = "tower-service"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"

[[package]]
name = "tower_sample"
version = "0.1.0"
dependencies = [
 "futures-core",
 "futures-util",
 "tower",
]

[[package]]
name = "tracing"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
dependencies = [
 "log",
 "pin-project-lite",
 "tracing-core",
]

[[package]]
name = "tracing-core"
version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
dependencies = [
 "once_cell",
]

[[package]]
name = "unicode-ident"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
Cargo.toml
[package]
name = "tower_sample"
version = "0.1.0"
edition = "2021"

[dependencies]
tower = { version = "=0.4.13", features = ["util"] }
futures-core = "0.3"
futures-util = "0.3"
NOTES.md
# Tower CallAll Pending Stream Bugfix

## search_known_solution result
`search_known_solution` returned no exact matches for Tower bug fixes; it only returned three low-confidence compatible samples for unrelated crates and topics: PostgreSQL struct scanning via pgx (`sha256:4eb6eee48a60e79da9dcf4055256991997f094a1da19ee17cfe0697e6d6d7b32`), Axum stateful middleware (`sha256:0add9e86ea54fb151285ed7fff0ac6a073835d84159f6bfc43b6e447f030a7be`), and Axum request payload limits (`sha256:adda974ec2d465cadc36ee9ef527ef98de16a608778e9bc8b0d096f4e2d504a3`).

## What a model would have written instead
A model would write `let mut call_all = svc.call_all(request_stream);` and poll it, assuming `CallAll::poll_next` yields `Poll::Pending` when `request_stream` is not yet ready.

## How the wrong version fails
On `tower <= 0.4.12`, polling `CallAll` while the incoming request stream is pending fails loudly with an infinite busy-loop / runtime thread hang (100% CPU spin), because `CallAll::poll_next` omitted `return Poll::Pending;` in the `Poll::Pending` arm inside its polling loop.
csx.json
{"case":{"caseId":"case:sha256:1268064fbb5490d85d0b292778802f0ff5a4eb732110113e70ed86410e3c0fc2","contract":["let mut call_all = svc.call_all(futures_util::stream::pending::\u003c\u0026'static str\u003e());","let poll_result = Pin::new(\u0026mut call_all).poll_next(\u0026mut cx);","assert!(poll_result.is_pending());"],"goal":"Poll CallAll stream without hanging in an infinite loop when the request stream yields Pending","kind":"HOW","packages":["pkg:cargo/tower@0.4.13"],"schemaVersion":1,"symbols":["tower::ServiceExt::call_all","tower::util::CallAll"]},"contractCommand":["cargo","test","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","executionContext":"rust","language":"rust","os":"linux","packageManager":"cargo","runtime":"rust","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/tower@0.4.13"],"schemaVersion":1,"symbols":["tower::ServiceExt::call_all","tower::util::CallAll"],"verifierAdapter":"cargo@1"}
src/lib.rs
use std::convert::Infallible;
use std::future::{ready, Ready};
use std::pin::Pin;
use std::task::{Context, Poll};
use futures_core::Stream;
use tower::{service_fn, ServiceExt};

pub fn poll_pending_call_all() -> Poll<Option<Result<&'static str, tower::BoxError>>> {
    let svc = service_fn(|req: &'static str| -> Ready<Result<&'static str, Infallible>> {
        ready(Ok(req))
    });

    let stream = futures_util::stream::pending::<&'static str>();
    let mut call_all = svc.call_all(stream);

    let waker = futures_util::task::noop_waker_ref();
    let mut cx = Context::from_waker(waker);

    // In tower 0.4.12, CallAll::poll_next enters an infinite busy-loop when the
    // request stream yields Poll::Pending because it omitted `return Poll::Pending`.
    // In tower 0.4.13 (PR #656), it correctly yields Poll::Pending immediately.
    Pin::new(&mut call_all).poll_next(&mut cx)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn call_all_yields_pending_when_stream_is_pending() {
        let poll_result = poll_pending_call_all();
        assert!(poll_result.is_pending());
    }
}

오리진 시더

csx-seed