Repository navigation
Description
Summary
In 0.8, the client server-stream API ServerStream::message() returns a future that is not Send once instantiated with a concrete generated message/view type — even though ServerStream, the response view, StreamMessage, and the view handle are all Send. This makes it impossible to consume a server-streaming client response inside a Send task (tokio::spawn), which is the normal way to drive a request off the accept path on a multi-threaded runtime.
Interestingly, the generic message() is Send — the failure only appears after monomorphizing with a concrete generated V::Owned/V, so the trigger is in the generated-type instantiation, not in caller code.
Reproduction (self-contained, generated code only)
No hand-written message types; a trivial server-streaming service compiled by connectrpc-build, consumed with the canonical stream.message().await pattern.
Cargo.toml:
[package]
name = "cr-send-repro-gen"
version = "0.0.0"
edition = "2021"
[dependencies]
connectrpc = { version = "0.8.0", features = ["client"] }
buffa = { version = "0.8", features = ["std", "json"] }
bytes = "1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
[build-dependencies]
connectrpc-build = "0.8.0"proto/repro.proto:
syntax = "proto3";
package repro.v1;
message Ping { string note = 1; }
message Pong {
string note = 1;
oneof kind { Ping echo = 2; }
}
service ReproService {
rpc Stream(Ping) returns (stream Pong);
}build.rs:
fn main() -> Result<(), Box<dyn std::error::Error>> {
connectrpc_build::Config::new()
.files(&["proto/repro.proto"])
.includes(&["proto/"])
.generate_json(true)
.include_file("_connectrpc.rs")
.compile()?;
Ok(())
}src/lib.rs:
pub mod proto {
connectrpc::include_generated!();
}
use proto::repro::v1::{Pong, PongView};
fn is_send<T: Send>() {}
fn snd<T: Send>(_: T) {}
pub fn repro<B>(mut stream: connectrpc::client::ServerStream<B, PongView<'static>>)
where
B: connectrpc::http_body::Body<Data = bytes::Bytes> + Send + Unpin + 'static,
B::Error: std::fmt::Display,
{
// All the data types are `Send`:
is_send::<connectrpc::client::ServerStream<B, PongView<'static>>>();
is_send::<PongView<'static>>();
is_send::<connectrpc::StreamMessage<Pong>>();
is_send::<<Pong as connectrpc::HasMessageView>::ViewHandle>();
// ...but the `message()` future is NOT `Send` — this line fails to compile:
snd(async move {
let _ = stream.message().await;
});
}cargo check fails only on the message().await block; the four is_send::<…>() assertions above it all pass.
Diagnostics
Stable rustc 1.95.0 and 1.96.1 (current trait solver):
error: implementation of `MessageView` is not general enough
--> src/lib.rs:27:5
|
27 | / snd(async move {
28 | | let _ = stream.message().await;
29 | | });
| |______^ implementation of `MessageView` is not general enough
|
= note: `MessageView<'static>` would have to be implemented for the type `PongView<'0>`, for any lifetime `'0`...
= note: ...but `MessageView<'1>` is actually implemented for the type `PongView<'1>`, for some specific lifetime `'1`
Nightly with the next-generation trait solver (RUSTFLAGS="-Znext-solver=globally"), which reports it as a genuine non-Send rather than a lifetime-generality failure:
error[E0277]: `{coroutine witness@src/lib.rs:27:9: 27:19}` cannot be sent between threads safely
--> src/lib.rs:27:5
= help: within `{async block@…}`, the trait `Send` is not implemented for `{coroutine witness@…}`
What I narrowed down
ServerStream<B, PongView<'static>>,PongView<'static>,StreamMessage<Pong>, and<Pong as HasMessageView>::ViewHandleare allSend(the assertions pass).- A version of
message()where the response view is a generic parameter boundedV: MessageView<'static> + Send/V::Owned: … + HasMessageView<View<'static> = V> + SendisSend— so the non-Sendonly appears when monomorphized against a concrete generated view. (I can share that generic variant too.) - The only awaits inside
message()'s call graph (next_message_or_end→poll_body→with_deadline(… body.frame().await)) hold&mut self, andServerStreamisSend, so it isn't obvious from the source why the monomorphized future losesSend. It looks like an interaction between themessage()boundRespView::Owned: HasMessageView<View<'static> = RespView>and auto-trait inference over the generatedView<'a>GAT.
Impact
There is no other public API to pull messages off a client ServerStream, so a streaming client cannot be consumed inside tokio::spawn or any Send-bounded task with concrete generated types. The equivalent server-streaming client consumption compiled fine in a spawned Send context under 0.7.
Questions
- Is
ServerStream::message()intended to be usable inside aSendtask? If not, is there a supported pattern for driving a client server-stream off the accept path on a multi-threaded runtime? - If it is intended, the concrete-monomorphization
!Sendlooks like a regression / codegen-interaction bug — happy to test a patch or provide the generic-vs-concrete variants side by side.
Environment: connectrpc/connectrpc-build 0.8.0, buffa 0.8.1, rustc 1.95.0 / 1.96.1 (stable) and 1.96.0-nightly.
Activity
christopherwxyz commentedon Jul 2, 2026
Checked how the repo's own examples/tests consume streams, since the asymmetry seems relevant to whether this is intended:
ServerStream(.message().await) is consumed inline on the task that opened it everywhere it appears —examples/streaming-tour/src/client.rs,examples/eliza/src/client.rs,tests/streaming/src/lib.rs. It's never moved into atokio::spawn.ServiceStream<StreamMessage<…>>(.next().await), by contrast, is spawned into a background task in everybidi_streamhandler, with an explicit comment that it'sSend + 'staticso it "can be moved into a spawned task and read zero-copy there" (tests/streaming/src/lib.rs).So the non-
Sendclient future lines up with a codebase where client streams are only ever consumed inline. The question is whether that's intended (clientServerStreamis inline-only by design) or an oversight given the server-side stream is deliberately Send-spawnable. The blocking use case is a client that spawns the stream consumer off the accept path (e.g. fast-ack a webhook, then drive the turn in a task) — which needs the client future to beSend, and no public API other than.message()exists to pull items.iainmcgin commentedon Jul 2, 2026
thanks for reporting, this is an important ergonomics issue and I'm investigating now
christopherwxyz commentedon Jul 2, 2026
No problem!
As well, happy to contribute a PR.
iainmcgin commentedon Jul 2, 2026
[claude code] Confirmed and fixed in #215 — thank you for an outstanding report; the generic-vs-concrete isolation pointed directly at the cause. The 0.8.0 bound on
message()projectedRespView::Ownedin the where-clause, which trips rustc's coroutine-witness auto-trait check on monomorphization (your nightly-Znext-solverdiagnosis was exactly right). The fix reshapes it as an output type parameter —message<M>() where RespView: MessageView<'static, Owned = M>, M: HasMessageView<View<'static> = RespView>— which is equivalent for every caller (Mis inferred) and restoresSend; verified against your exact repro shape including the message-typedoneof, plus a live spawned consumer over server-stream/bidi/mid-stream-error paths. To answer your question 1 directly: yes, consuming a stream insidetokio::spawnis absolutely intended usage — this was a regression, not a design choice. It will ship as 0.8.1 shortly after #215 lands.iainmcgin commentedon Jul 2, 2026
Should be fixed with 0.8.1 - can you verify, @christopherwxyz ?
iainmcgin commentedon Jul 2, 2026
[claude code] connectrpc 0.8.1 is on crates.io with the fix — a plain
cargo updatepicks it up (the"0.8"/"0.8.0"requirements both resolve to it). Your repro pattern is also now a permanent compile-time regression pin in CI, asserted through the exacttokio::spawn-shaped coroutine where the failure manifests (interestingly, assertingSendon the baremessage()future passes even with the buggy bound — the failure lives in the enclosing coroutine's witness, which your report's spawn-shaped repro captured exactly right). Thanks again for the isolation quality; it turned this around in about a day.christopherwxyz commentedon Jul 2, 2026
Yes! It worked.
🫡
client: restore Send on stream message() futures with concrete view t…
release: v0.8.1 (connectrpc#216)