ConnectRpcService panics on any request timeout when the executor is not Tokio

Open
#326 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
rust

Research direction

Start with the timeout paths in src/service.rs and src/deadline.rs, then trace the detached-task handling described in src/lib.rs. Run the supplied connectrpc/tests/no_runtime.rs reproduction on futures::executor::block_on and Tokio. Done means timeout and deadline-policy calls, streaming responses, and request-body draining work without a Tokio runtime panic.

Written by the indexing model from the issue text.

Description

ConnectRpcService is a tower::Service over any http_body::Body, so nothing in its signature ties it to an executor. It needs an ambient Tokio runtime for two things. The first is every timer: tokio::time::timeout_at, timeout and sleep. The second is the detached task that drains an unread request body. When another executor polls the service, a request panics if it has a timeout, from a header or from the DeadlinePolicy. A streaming response under DeadlinePolicy::with_inter_message_timeout panics too. The drain task is dropped without a log line. A request with no timeout and no such policy is served correctly.

The crate already solves half of this problem for one target: on wasm32, spawn_detached calls wasm_bindgen_futures::spawn_local (#63). This issue asks for the same ability on every target, for both the spawner and the timer. The service could then run on an executor other than Tokio, such as a single-threaded or embedded one.

Versions

I ran everything under "What happens on main" on main at fb5f5aaf0ad6ada4485ba5aa38a078a929073158 (2026-09-26, 31 commits after v0.9.0). The build used default features, tokio 1.53.1 and futures-executor 0.3.34, on Linux x86_64. The executor is futures::executor::block_on, from the futures crate that connectrpc already depends on.

I ran the same program on the v0.9.1 tag, which is on the release-0.9 branch and does not contain #299. There the unary and server-streaming calls panic in the same cases, at src/service.rs:321 and src/deadline.rs:364. Every client-streaming and bidi call panics at src/lib.rs:182, with or without a timeout, because that release decodes the request body on a task that it starts with tokio::spawn. #299 moved the decoding into the handler's task. On main, spawn_detached calls Handle::try_current() and drops the future outside a runtime, so that panic is gone.

Reproduction

The shortest case is a unary call with a timeout header:

use buffa_types::Empty;
use bytes::Bytes;
use connectrpc::{ConnectRpcService, RequestContext, Response, Router, handler_fn};
use tower::Service as _;

#[test]
fn unary_call_with_a_timeout_header() {
    let router = Router::new().route(
        "svc",
        "Unary",
        handler_fn(|_ctx: RequestContext, _req: Empty| async { Response::ok(Empty::default()) }),
    );
    let mut service = ConnectRpcService::new(router);
    let request = http::Request::post("/svc/Unary")
        .header("content-type", "application/proto")
        .header("connect-timeout-ms", "5000")
        .body(http_body_util::Empty::<Bytes>::new())
        .unwrap();

    let response = futures::executor::block_on(service.call(request)).unwrap();

    assert_eq!(response.status(), http::StatusCode::OK);
}
thread 'unary_call_with_a_timeout_header' panicked at connectrpc/src/service.rs:315:27:
there is no reactor running, must be called from the context of a Tokio 1.x runtime

The program below makes each kind of call on block_on, then makes the same calls on a current-thread Tokio runtime for comparison. Its request body counts the frames that the service reads, and the frames that are still unread when the service drops the body. Save it as connectrpc/tests/no_runtime.rs in a checkout of main and run cargo test -p connectrpc --test no_runtime -- --nocapture. Every crate that it uses is already a dependency of connectrpc.

Reproduction source code (connectrpc/tests/no_runtime.rs)
//! Drives `ConnectRpcService` as a `tower::Service` on an executor that is
//! not Tokio (`futures::executor::block_on`), then on Tokio, and prints what
//! each call shape does. Run with:
//!
//! ```sh
//! cargo test -p connectrpc --test no_runtime -- --nocapture
//! ```

use std::cell::RefCell;
use std::collections::VecDeque;
use std::convert::Infallible;
use std::panic::AssertUnwindSafe;
use std::pin::Pin;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::task::{Context, Poll};
use std::time::Duration;

use buffa_types::Empty;
use bytes::Bytes;
use connectrpc::deadline::DeadlinePolicy;
use connectrpc::{
    ConnectError, ConnectRpcService, RequestContext, Response, Router, ServiceStream,
    bidi_streaming_handler_fn, client_streaming_handler_fn, handler_fn, streaming_handler_fn,
};
use futures::StreamExt as _;
use http_body::{Body, Frame};
use http_body_util::BodyExt as _;
use tower::Service as _;

thread_local! {
    static LAST_PANIC: RefCell<Option<String>> = const { RefCell::new(None) };
}

/// What the request body saw: how many frames the service read, and how many
/// were still unread when the service dropped the body.
#[derive(Default)]
struct Probe {
    frames_read: AtomicUsize,
    unread_at_drop: AtomicUsize,
}

struct ProbeBody {
    frames: VecDeque<Bytes>,
    probe: Arc<Probe>,
}

impl Body for ProbeBody {
    type Data = Bytes;
    type Error = Infallible;

    fn poll_frame(
        mut self: Pin<&mut Self>,
        _cx: &mut Context<'_>,
    ) -> Poll<Option<Result<Frame<Bytes>, Infallible>>> {
        let next = self.frames.pop_front();
        if next.is_some() {
            self.probe.frames_read.fetch_add(1, Ordering::SeqCst);
        }
        Poll::Ready(next.map(|data| Ok(Frame::data(data))))
    }

    fn is_end_stream(&self) -> bool {
        self.frames.is_empty()
    }
}

impl Drop for ProbeBody {
    fn drop(&mut self) {
        self.probe
            .unread_at_drop
            .store(self.frames.len(), Ordering::SeqCst);
    }
}

/// One envelope that holds an empty message.
const ENVELOPE: &[u8] = &[0, 0, 0, 0, 0];

fn router() -> Router {
    Router::new()
        .route(
            "svc",
            "Unary",
            handler_fn(|_ctx: RequestContext, _req: Empty| async {
                Response::ok(Empty::default())
            }),
        )
        .route_server_stream(
            "svc",
            "ServerStream",
            streaming_handler_fn(|_ctx: RequestContext, _req: Empty| async {
                Response::stream_ok(futures::stream::iter([
                    Ok::<_, ConnectError>(Empty::default()),
                    Ok(Empty::default()),
                ]))
            }),
        )
        .route_client_stream(
            "svc",
            "ClientStream",
            client_streaming_handler_fn(
                |_ctx: RequestContext, mut requests: ServiceStream<Empty>| async move {
                    while let Some(message) = requests.next().await {
                        message?;
                    }
                    Response::ok(Empty::default())
                },
            ),
        )
        .route_client_stream(
            "svc",
            "ClientStreamReadsOne",
            client_streaming_handler_fn(
                |_ctx: RequestContext, mut requests: ServiceStream<Empty>| async move {
                    if let Some(message) = requests.next().await {
                        message?;
                    }
                    Response::ok(Empty::default())
                },
            ),
        )
        .route_bidi_stream(
            "svc",
            "Bidi",
            bidi_streaming_handler_fn(
                |_ctx: RequestContext, requests: ServiceStream<Empty>| async move {
                    Response::stream_ok(requests)
                },
            ),
        )
        .route_bidi_stream(
            "svc",
            "BidiReadsOne",
            bidi_streaming_handler_fn(
                |_ctx: RequestContext, requests: ServiceStream<Empty>| async move {
                    Response::stream_ok(requests.take(1))
                },
            ),
        )
}

struct Case {
    name: &'static str,
    path: &'static str,
    content_type: &'static str,
    headers: &'static [(&'static str, &'static str)],
    frames: usize,
    policy: Option<DeadlinePolicy>,
}

impl Case {
    fn request(&self) -> (http::Request<ProbeBody>, Arc<Probe>) {
        let probe = Arc::new(Probe::default());
        let body = ProbeBody {
            frames: (0..self.frames)
                .map(|_| Bytes::from_static(ENVELOPE))
                .collect(),
            probe: Arc::clone(&probe),
        };
        let mut request = http::Request::builder()
            .method(http::Method::POST)
            .uri(self.path)
            .header("content-type", self.content_type);
        for (name, value) in self.headers {
            request = request.header(*name, *value);
        }
        (request.body(body).unwrap(), probe)
    }

    fn service(&self) -> ConnectRpcService {
        let service = ConnectRpcService::new(router());
        match &self.policy {
            Some(policy) => service.with_deadline_policy(policy.clone()),
            None => service,
        }
    }
}

/// Make the call and read the whole response body.
async fn call(case: &Case) -> (String, Arc<Probe>) {
    let (request, probe) = case.request();
    let response = case.service().call(request).await.unwrap();
    let status = response.status();
    let body = response.into_body().collect().await;
    let outcome = match body {
        Ok(collected) => {
            let trailers = collected.trailers().cloned();
            let bytes = collected.to_bytes();
            format!(
                "HTTP {status}, {} body bytes: {:?}{}",
                bytes.len(),
                String::from_utf8_lossy(&bytes),
                trailers.map_or_else(String::new, |t| format!(", trailers {t:?}")),
            )
        }
        Err(error) => format!("HTTP {status}, body error: {error}"),
    };
    (outcome, probe)
}

fn report(executor: &str, case: &Case, run: impl FnOnce() -> (String, Arc<Probe>)) {
    LAST_PANIC.with_borrow_mut(|last| *last = None);
    let result = std::panic::catch_unwind(AssertUnwindSafe(run));
    print!("[{executor}] {}: ", case.name);
    match result {
        Ok((outcome, probe)) => println!(
            "{outcome}; request frames read {} of {}, unread when the body was dropped {}",
            probe.frames_read.load(Ordering::SeqCst),
            case.frames,
            probe.unread_at_drop.load(Ordering::SeqCst),
        ),
        Err(_) => println!(
            "PANIC {}",
            LAST_PANIC
                .with_borrow_mut(Option::take)
                .unwrap_or_else(|| "(no message)".to_owned())
        ),
    }
}

#[test]
fn every_call_shape_on_block_on_and_on_tokio() {
    std::panic::set_hook(Box::new(|info| {
        let message = info
            .payload()
            .downcast_ref::<&str>()
            .map(|s| (*s).to_owned())
            .or_else(|| info.payload().downcast_ref::<String>().cloned())
            .unwrap_or_default();
        let location = info
            .location()
            .map(|l| format!("{}:{}:{}", l.file(), l.line(), l.column()))
            .unwrap_or_default();
        LAST_PANIC.with_borrow_mut(|last| *last = Some(format!("at {location}: {message}")));
    }));

    const TIMEOUT: &[(&str, &str)] = &[("connect-timeout-ms", "5000")];
    const GRPC_TIMEOUT: &[(&str, &str)] = &[("grpc-timeout", "5S"), ("te", "trailers")];
    const PROTO: &str = "application/proto";
    const STREAM: &str = "application/connect+proto";

    let case = |name, path, content_type, headers, frames| Case {
        name,
        path,
        content_type,
        headers,
        frames,
        policy: None,
    };
    let cases = [
        case("unary", "/svc/Unary", PROTO, &[], 0),
        case("unary, connect-timeout-ms", "/svc/Unary", PROTO, TIMEOUT, 0),
        case(
            "unary, gRPC, grpc-timeout",
            "/svc/Unary",
            "application/grpc+proto",
            GRPC_TIMEOUT,
            1,
        ),
        Case {
            policy: Some(DeadlinePolicy::new().with_default_timeout(Duration::from_secs(5))),
            ..case(
                "unary, no timeout header, DeadlinePolicy default timeout",
                "/svc/Unary",
                PROTO,
                &[],
                0,
            )
        },
        case(
            "unknown method, connect-timeout-ms",
            "/svc/Missing",
            PROTO,
            TIMEOUT,
            1,
        ),
        case("server-streaming", "/svc/ServerStream", STREAM, &[], 1),
        case(
            "server-streaming, connect-timeout-ms",
            "/svc/ServerStream",
            STREAM,
            TIMEOUT,
            1,
        ),
        Case {
            policy: Some(DeadlinePolicy::new().with_inter_message_timeout(Duration::from_secs(5))),
            ..case(
                "server-streaming, DeadlinePolicy inter-message timeout",
                "/svc/ServerStream",
                STREAM,
                &[],
                1,
            )
        },
        case(
            "client-streaming, handler reads all",
            "/svc/ClientStream",
            STREAM,
            &[],
            3,
        ),
        case(
            "client-streaming, handler reads one of three",
            "/svc/ClientStreamReadsOne",
            STREAM,
            &[],
            3,
        ),
        case(
            "client-streaming, connect-timeout-ms",
            "/svc/ClientStream",
            STREAM,
            TIMEOUT,
            3,
        ),
        case("bidi, handler reads all", "/svc/Bidi", STREAM, &[], 3),
        case(
            "bidi, handler reads one of three",
            "/svc/BidiReadsOne",
            STREAM,
            &[],
            3,
        ),
        case("bidi, connect-timeout-ms", "/svc/Bidi", STREAM, TIMEOUT, 3),
    ];

    for case in &cases {
        report("block_on", case, || futures::executor::block_on(call(case)));
    }

    // The same calls on a Tokio runtime, for comparison.
    let runtime = tokio::runtime::Builder::new_current_thread()
        .enable_time()
        .build()
        .unwrap();
    for case in &cases {
        report("tokio", case, || {
            runtime.block_on(async {
                let outcome = call(case).await;
                // Let a detached drain task run.
                for _ in 0..8 {
                    tokio::task::yield_now().await;
                }
                outcome
            })
        });
    }
    drop(std::panic::take_hook());
}
Reproduction output on main at fb5f5aa
[block_on] unary: HTTP 200 OK, 0 body bytes: ""; request frames read 0 of 0, unread when the body was dropped 0
[block_on] unary, connect-timeout-ms: PANIC at connectrpc/src/service.rs:315:27: there is no reactor running, must be called from the context of a Tokio 1.x runtime
[block_on] unary, gRPC, grpc-timeout: PANIC at connectrpc/src/service.rs:315:27: there is no reactor running, must be called from the context of a Tokio 1.x runtime
[block_on] unary, no timeout header, DeadlinePolicy default timeout: PANIC at connectrpc/src/service.rs:315:27: there is no reactor running, must be called from the context of a Tokio 1.x runtime
[block_on] unknown method, connect-timeout-ms: PANIC at connectrpc/src/service.rs:315:27: there is no reactor running, must be called from the context of a Tokio 1.x runtime
[block_on] server-streaming: HTTP 200 OK, 17 body bytes: "\0\0\0\0\0\0\0\0\0\0\u{2}\0\0\0\u{2}{}"; request frames read 1 of 1, unread when the body was dropped 0
[block_on] server-streaming, connect-timeout-ms: PANIC at connectrpc/src/service.rs:315:27: there is no reactor running, must be called from the context of a Tokio 1.x runtime
[block_on] server-streaming, DeadlinePolicy inter-message timeout: PANIC at connectrpc/src/deadline.rs:364:36: there is no reactor running, must be called from the context of a Tokio 1.x runtime
[block_on] client-streaming, handler reads all: HTTP 200 OK, 12 body bytes: "\0\0\0\0\0\u{2}\0\0\0\u{2}{}"; request frames read 3 of 3, unread when the body was dropped 0
[block_on] client-streaming, handler reads one of three: HTTP 200 OK, 12 body bytes: "\0\0\0\0\0\u{2}\0\0\0\u{2}{}"; request frames read 1 of 3, unread when the body was dropped 2
[block_on] client-streaming, connect-timeout-ms: PANIC at connectrpc/src/service.rs:2797:15: there is no reactor running, must be called from the context of a Tokio 1.x runtime
[block_on] bidi, handler reads all: HTTP 200 OK, 22 body bytes: "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\u{2}\0\0\0\u{2}{}"; request frames read 3 of 3, unread when the body was dropped 0
[block_on] bidi, handler reads one of three: HTTP 200 OK, 12 body bytes: "\0\0\0\0\0\u{2}\0\0\0\u{2}{}"; request frames read 1 of 3, unread when the body was dropped 2
[block_on] bidi, connect-timeout-ms: PANIC at connectrpc/src/service.rs:3215:15: there is no reactor running, must be called from the context of a Tokio 1.x runtime
[tokio] unary: HTTP 200 OK, 0 body bytes: ""; request frames read 0 of 0, unread when the body was dropped 0
[tokio] unary, connect-timeout-ms: HTTP 200 OK, 0 body bytes: ""; request frames read 0 of 0, unread when the body was dropped 0
[tokio] unary, gRPC, grpc-timeout: HTTP 200 OK, 5 body bytes: "\0\0\0\0\0", trailers {"grpc-status": "0"}; request frames read 1 of 1, unread when the body was dropped 0
[tokio] unary, no timeout header, DeadlinePolicy default timeout: HTTP 200 OK, 0 body bytes: ""; request frames read 0 of 0, unread when the body was dropped 0
[tokio] unknown method, connect-timeout-ms: HTTP 404 Not Found, 66 body bytes: "{\"code\":\"unimplemented\",\"message\":\"method not found: svc/Missing\"}"; request frames read 1 of 1, unread when the body was dropped 0
[tokio] server-streaming: HTTP 200 OK, 17 body bytes: "\0\0\0\0\0\0\0\0\0\0\u{2}\0\0\0\u{2}{}"; request frames read 1 of 1, unread when the body was dropped 0
[tokio] server-streaming, connect-timeout-ms: HTTP 200 OK, 17 body bytes: "\0\0\0\0\0\0\0\0\0\0\u{2}\0\0\0\u{2}{}"; request frames read 1 of 1, unread when the body was dropped 0
[tokio] server-streaming, DeadlinePolicy inter-message timeout: HTTP 200 OK, 17 body bytes: "\0\0\0\0\0\0\0\0\0\0\u{2}\0\0\0\u{2}{}"; request frames read 1 of 1, unread when the body was dropped 0
[tokio] client-streaming, handler reads all: HTTP 200 OK, 12 body bytes: "\0\0\0\0\0\u{2}\0\0\0\u{2}{}"; request frames read 3 of 3, unread when the body was dropped 0
[tokio] client-streaming, handler reads one of three: HTTP 200 OK, 12 body bytes: "\0\0\0\0\0\u{2}\0\0\0\u{2}{}"; request frames read 3 of 3, unread when the body was dropped 0
[tokio] client-streaming, connect-timeout-ms: HTTP 200 OK, 12 body bytes: "\0\0\0\0\0\u{2}\0\0\0\u{2}{}"; request frames read 3 of 3, unread when the body was dropped 0
[tokio] bidi, handler reads all: HTTP 200 OK, 22 body bytes: "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\u{2}\0\0\0\u{2}{}"; request frames read 3 of 3, unread when the body was dropped 0
[tokio] bidi, handler reads one of three: HTTP 200 OK, 12 body bytes: "\0\0\0\0\0\u{2}\0\0\0\u{2}{}"; request frames read 3 of 3, unread when the body was dropped 0
[tokio] bidi, connect-timeout-ms: HTTP 200 OK, 22 body bytes: "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\u{2}\0\0\0\u{2}{}"; request frames read 3 of 3, unread when the body was dropped 0

What happens on main

Call, polled by block_on Result
Unary, no timeout HTTP 200
Unary with connect-timeout-ms, with grpc-timeout, or with no header and DeadlinePolicy::with_default_timeout Panic at src/service.rs:315
Request for an unknown method, with connect-timeout-ms Panic at src/service.rs:315. On Tokio the response is HTTP 404.
Server-streaming, no timeout HTTP 200, both messages
Server-streaming with connect-timeout-ms Panic at src/service.rs:315
Server-streaming with DeadlinePolicy::with_inter_message_timeout Panic at src/deadline.rs:364
Client-streaming or bidi, no timeout, handler reads the whole request stream HTTP 200
Client-streaming or bidi, no timeout, handler stops after one of three messages HTTP 200. The body is dropped with two frames unread. On Tokio the drain reads all three.
Client-streaming with connect-timeout-ms Panic at src/service.rs:2797
Bidi with connect-timeout-ms Panic at src/service.rs:3215

Every panic has the message there is no reactor running, must be called from the context of a Tokio 1.x runtime. The panic unwinds out of the future that Service::call returned. A client sends the timeout header whenever its caller sets a deadline, so a service on another executor panics on ordinary traffic. A request with a timeout header for a method that the service does not have panics too, before the 404.

The dropped drain changes nothing in the response. The doc comment on request_body_drain (src/service.rs:3087) gives the cost of a body that is dropped unread. On HTTP/1.1, hyper closes the connection. On HTTP/2, the unread DATA frames count against budgets that the whole connection shares. hyper 1.x runs on other executors through hyper::rt, and an integrator who runs it that way pays this cost with no log line.

Where in the source

Line numbers are for connectrpc/ on main at fb5f5aa. The table covers the server path (service.rs, deadline.rs, and spawn_detached in lib.rs) as default features compile it, outside #[cfg(test)]. The client module also compiles with default features, and its call sites are under "Out of scope".

Location Call Reached when
src/service.rs:315, in with_request_deadline tokio::time::timeout_at A unary or server-streaming request has a timeout, from a header or from DeadlinePolicy. The callers are in handle_unary_request, handle_grpc_unary_request and handle_streaming_request. The unknown-method case above panics from the call at line 2010. Three more callers reject a request before dispatch, and I did not run them: an unsupported content type (line 1750), gRPC-Web text mode (line 1804) and an unsupported HTTP method (line 1954).
src/service.rs:2797 tokio::time::timeout A client-streaming request has a timeout.
src/service.rs:3215 tokio::time::timeout A bidi request has a timeout.
src/deadline.rs:334, 364, 399, in DeadlineStream tokio::time::sleep A server-streaming or bidi response. Line 334: the policy sets with_enforce_on_streams and the request has a deadline, so the request has already panicked at line 315 or 3215. Lines 364 and 399: the policy sets with_inter_message_timeout. I ran only the case that reaches line 364.
src/service.rs:2942, in decode_request_body Handle::try_current().ok() Every client-streaming and bidi request. It does not panic.
src/service.rs:2986 and 2989, src/lib.rs:191 Handle::spawn, or the future is dropped A request stream reaches END_STREAM or a decode error, or is dropped before the body ends.
src/service.rs:2899, in drain_timeout tokio::time::sleep Inside the drain future. On main only Tokio polls the drain. If the integrator supplied the spawner alone, the panic would move here, so the integrator has to supply the timer too.
src/service.rs:3110 tokio::select! Inside the drain future. The macro needs the tokio crate to compile, and needs no runtime.

A server that serves unary calls alone reaches only src/service.rs:315.

On wasm32 the spawn has its own implementation, and drain_timeout returns std::future::pending(). The three timer calls in service.rs and the calls in deadline.rs have no cfg for wasm32. I read that in the source and did not run it.

Request

Let the integrator supply two functions to ConnectRpcService: one that spawns a detached Future<Output = ()>, and one that returns a future that completes at a deadline. The service then uses those functions for the deadlines and the drain, in place of direct calls to Tokio. Tokio stays the default, so that an existing user changes nothing.

hyper 1.x has the same split in hyper::rt::Executor and hyper::rt::Timer.

Possible designs

A trait that the service holds
pub trait Runtime: Send + Sync + 'static {
    /// Run `future` to completion in the background.
    fn spawn(&self, future: BoxFuture<'static, ()>);
    /// A future that completes at `deadline`.
    fn sleep_until(&self, deadline: std::time::Instant) -> BoxFuture<'static, ()>;
}

impl<D> ConnectRpcService<D> {
    pub fn with_runtime(self, runtime: Arc<dyn Runtime>) -> Self;
}

The crate provides the Tokio implementation and uses it when with_runtime is not called. The wasm32 branch of spawn_detached becomes one more implementation of the trait. The bounds follow the service, whose futures are Send today. An executor whose spawner is !Send needs a wrapper, or a variant of the trait without the bound, as spawn_detached has for wasm32.

Cost to existing users: no change to source. Each timer becomes a boxed future. A request without a deadline arms no timer, but DeadlineStream arms the inter-message timer again after every message, so a service that sets with_inter_message_timeout allocates once for each streamed message. A reset method on the trait, like the one on hyper::rt::Timer, removes that allocation. The service can also keep the concrete tokio::time::Sleep when the runtime is the default one.

A type parameter, ConnectRpcService<D, R = Tokio>, removes the boxing. It costs more API: a signature that accepts a runtime other than the default must have the parameter. Existing signatures, such as Server::from_service, keep compiling through the default.

A cargo feature for the Tokio runtime

The Tokio implementation moves behind a feature that is on by default, for example tokio-runtime. ConnectRpcService::new requires the feature, and a constructor that takes the runtime is always available. The features stay additive, because the feature only adds the default constructor.

Cost to existing users: none with default features. A user who sets default-features = false must add the feature, which is a breaking change for that user.

This design needs the trait from the first one. It adds one property: a service with no runtime fails to compile, where today it panics at run time.

Out of scope

  • The server and axum features. The accept loop and the connection driver are written for Tokio and hyper, and can stay that way.
  • The client module. It compiles with default features, and only its hyper transports need the client feature. It calls tokio::spawn (src/client/mod.rs:3932 and 4214) and tokio::time::timeout_at (line 1618). It needs the same treatment, but as a separate change.
  • Removing tokio from the dependency tree. tokio::select! in the drain, tokio_util::codec::Encoder in src/envelope.rs and tokio::sync::mpsc in the client run on any executor.
  • no_std.
Dominant language
Rust
Stars
544
Forks
77
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from connectrpc/connect-rust

All issues in connectrpc/connect-rust

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.