Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix http2_keepalive panics on the client side #1730

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion tests/integration_tests/tests/http2_keep_alive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::time::Duration;
use tokio::sync::oneshot;

use integration_tests::pb::{test_client::TestClient, test_server, Input, Output};
use tonic::{transport::Server, Request, Response, Status};
use tonic::transport::{Channel, Server};
use tonic::{Request, Response, Status};

struct Svc;

Expand Down Expand Up @@ -38,3 +39,33 @@ async fn http2_keepalive_does_not_cause_panics() {
tx.send(()).unwrap();
jh.await.unwrap();
}

#[tokio::test]
async fn http2_keepalive_does_not_cause_panics_on_client_side() {
let svc = test_server::TestServer::new(Svc {});
let (tx, rx) = oneshot::channel::<()>();
let jh = tokio::spawn(async move {
Server::builder()
.http2_keepalive_interval(Some(Duration::from_secs(5)))
.add_service(svc)
.serve_with_shutdown("127.0.0.1:5431".parse().unwrap(), async { drop(rx.await) })
.await
.unwrap();
});

tokio::time::sleep(Duration::from_millis(100)).await;

let channel = Channel::from_static("http://127.0.0.1:5431")
.http2_keep_alive_interval(Duration::from_secs(5))
.connect()
.await
.unwrap();
let mut client = TestClient::new(channel);

let res = client.unary_call(Request::new(Input {})).await;

assert!(res.is_ok());

tx.send(()).unwrap();
jh.await.unwrap();
}
2 changes: 2 additions & 0 deletions tonic/src/transport/service/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
use http::Uri;
use hyper::rt;
use hyper::{client::conn::http2::Builder, rt::Executor};
use hyper_util::rt::TokioTimer;
use std::{
fmt,
task::{Context, Poll},
Expand Down Expand Up @@ -39,6 +40,7 @@ impl Connection {
.initial_stream_window_size(endpoint.init_stream_window_size)
.initial_connection_window_size(endpoint.init_connection_window_size)
.keep_alive_interval(endpoint.http2_keep_alive_interval)
.timer(TokioTimer::new())
.clone();

if let Some(val) = endpoint.http2_keep_alive_timeout {
Expand Down