Skip to content

Commit

Permalink
Merge branch 'master' into fix/tls-codegen-failure
Browse files Browse the repository at this point in the history
  • Loading branch information
mkatychev committed Aug 20, 2024
2 parents de5cec8 + 086bcd2 commit 74a42fb
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 31 deletions.
18 changes: 7 additions & 11 deletions tonic-build/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub(crate) fn generate_internal<T: Service>(
generate_doc_comments(service.comment())
};

let named = generate_named(&server_service, &server_trait, &service_name);
let named = generate_named(&server_service, &service_name);
let mod_attributes = attributes.for_mod(package);
let struct_attributes = attributes.for_struct(&service_name);

Expand Down Expand Up @@ -110,15 +110,15 @@ pub(crate) fn generate_internal<T: Service>(
#service_doc
#(#struct_attributes)*
#[derive(Debug)]
pub struct #server_service<T: #server_trait> {
pub struct #server_service<T> {
inner: Arc<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}

impl<T: #server_trait> #server_service<T> {
impl<T> #server_service<T> {
pub fn new(inner: T) -> Self {
Self::from_arc(Arc::new(inner))
}
Expand Down Expand Up @@ -175,7 +175,7 @@ pub(crate) fn generate_internal<T: Service>(
}
}

impl<T: #server_trait> Clone for #server_service<T> {
impl<T> Clone for #server_service<T> {
fn clone(&self) -> Self {
let inner = self.inner.clone();
Self {
Expand Down Expand Up @@ -352,19 +352,15 @@ fn generate_trait_methods<T: Service>(
stream
}

fn generate_named(
server_service: &syn::Ident,
server_trait: &syn::Ident,
service_name: &str,
) -> TokenStream {
fn generate_named(server_service: &syn::Ident, service_name: &str) -> TokenStream {
let service_name = syn::LitStr::new(service_name, proc_macro2::Span::call_site());
let name_doc = generate_doc_comment(" Generated gRPC service name");

quote! {
#name_doc
pub const SERVICE_NAME: &'static str = #service_name;
pub const SERVICE_NAME: &str = #service_name;

impl<T: #server_trait> tonic::server::NamedService for #server_service<T> {
impl<T> tonic::server::NamedService for #server_service<T> {
const NAME: &'static str = SERVICE_NAME;
}
}
Expand Down
10 changes: 5 additions & 5 deletions tonic-health/src/generated/grpc_health_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,14 @@ pub mod health_server {
) -> std::result::Result<tonic::Response<Self::WatchStream>, tonic::Status>;
}
#[derive(Debug)]
pub struct HealthServer<T: Health> {
pub struct HealthServer<T> {
inner: Arc<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
impl<T: Health> HealthServer<T> {
impl<T> HealthServer<T> {
pub fn new(inner: T) -> Self {
Self::from_arc(Arc::new(inner))
}
Expand Down Expand Up @@ -427,7 +427,7 @@ pub mod health_server {
}
}
}
impl<T: Health> Clone for HealthServer<T> {
impl<T> Clone for HealthServer<T> {
fn clone(&self) -> Self {
let inner = self.inner.clone();
Self {
Expand All @@ -440,8 +440,8 @@ pub mod health_server {
}
}
/// Generated gRPC service name
pub const SERVICE_NAME: &'static str = "grpc.health.v1.Health";
impl<T: Health> tonic::server::NamedService for HealthServer<T> {
pub const SERVICE_NAME: &str = "grpc.health.v1.Health";
impl<T> tonic::server::NamedService for HealthServer<T> {
const NAME: &'static str = SERVICE_NAME;
}
}
10 changes: 5 additions & 5 deletions tonic-reflection/src/generated/grpc_reflection_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,14 @@ pub mod server_reflection_server {
>;
}
#[derive(Debug)]
pub struct ServerReflectionServer<T: ServerReflection> {
pub struct ServerReflectionServer<T> {
inner: Arc<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
impl<T: ServerReflection> ServerReflectionServer<T> {
impl<T> ServerReflectionServer<T> {
pub fn new(inner: T) -> Self {
Self::from_arc(Arc::new(inner))
}
Expand Down Expand Up @@ -436,7 +436,7 @@ pub mod server_reflection_server {
}
}
}
impl<T: ServerReflection> Clone for ServerReflectionServer<T> {
impl<T> Clone for ServerReflectionServer<T> {
fn clone(&self) -> Self {
let inner = self.inner.clone();
Self {
Expand All @@ -449,8 +449,8 @@ pub mod server_reflection_server {
}
}
/// Generated gRPC service name
pub const SERVICE_NAME: &'static str = "grpc.reflection.v1.ServerReflection";
impl<T: ServerReflection> tonic::server::NamedService for ServerReflectionServer<T> {
pub const SERVICE_NAME: &str = "grpc.reflection.v1.ServerReflection";
impl<T> tonic::server::NamedService for ServerReflectionServer<T> {
const NAME: &'static str = SERVICE_NAME;
}
}
10 changes: 5 additions & 5 deletions tonic-reflection/src/generated/grpc_reflection_v1alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,14 @@ pub mod server_reflection_server {
>;
}
#[derive(Debug)]
pub struct ServerReflectionServer<T: ServerReflection> {
pub struct ServerReflectionServer<T> {
inner: Arc<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
impl<T: ServerReflection> ServerReflectionServer<T> {
impl<T> ServerReflectionServer<T> {
pub fn new(inner: T) -> Self {
Self::from_arc(Arc::new(inner))
}
Expand Down Expand Up @@ -436,7 +436,7 @@ pub mod server_reflection_server {
}
}
}
impl<T: ServerReflection> Clone for ServerReflectionServer<T> {
impl<T> Clone for ServerReflectionServer<T> {
fn clone(&self) -> Self {
let inner = self.inner.clone();
Self {
Expand All @@ -449,8 +449,8 @@ pub mod server_reflection_server {
}
}
/// Generated gRPC service name
pub const SERVICE_NAME: &'static str = "grpc.reflection.v1alpha.ServerReflection";
impl<T: ServerReflection> tonic::server::NamedService for ServerReflectionServer<T> {
pub const SERVICE_NAME: &str = "grpc.reflection.v1alpha.ServerReflection";
impl<T> tonic::server::NamedService for ServerReflectionServer<T> {
const NAME: &'static str = SERVICE_NAME;
}
}
2 changes: 1 addition & 1 deletion tonic-types/src/richer_error/std_messages/retry_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::super::{pb, FromAny, IntoAny};
/// [error_details.proto]: https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto
#[derive(Clone, Debug)]
pub struct RetryInfo {
/// Informs the amout of time that clients should wait before retrying.
/// Informs the amount of time that clients should wait before retrying.
pub retry_delay: Option<time::Duration>,
}

Expand Down
2 changes: 1 addition & 1 deletion tonic/src/codec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const DEFAULT_YIELD_THRESHOLD: usize = 32 * 1024;
/// together into one larger send(). The yield threshold controls how
/// much you want to bulk up such a batch of ready-to-send messages.
/// The larger your yield threshold the more you will batch - and
/// consequentially allocate contiguous memory, which might be relevant
/// consequently allocate contiguous memory, which might be relevant
/// if you're considering large numbers here.
/// If your server streaming rpc does not reach the yield threshold
/// before it reaches Poll::Pending (meaning, it's waiting for more
Expand Down
4 changes: 3 additions & 1 deletion tonic/src/transport/channel/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ impl Endpoint {
}
}

/// Sets the max header list size. Uses `hyper`'s default otherwise.
/// Sets the max size of received header frames.
///
/// This will default to whatever the default in hyper is. As of v1.4.1, it is 16 KiB.
pub fn http2_max_header_list_size(self, size: u32) -> Self {
Endpoint {
http2_max_header_list_size: Some(size),
Expand Down
18 changes: 16 additions & 2 deletions tonic/src/transport/server/incoming.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::service::ServerIo;
#[cfg(feature = "tls")]
use super::service::TlsAcceptor;
#[cfg(not(feature = "tls"))]
use std::io;
use std::{
net::{SocketAddr, TcpListener as StdTcpListener},
pin::{pin, Pin},
Expand All @@ -27,7 +29,19 @@ where
let mut incoming = pin!(incoming);

while let Some(item) = incoming.next().await {
yield item.map(ServerIo::new_io)?
yield match item {
Ok(_) => item.map(ServerIo::new_io)?,
Err(e) => {
let e = e.into();
tracing::debug!(error = %e, "accept loop error");
if let Some(e) = e.downcast_ref::<io::Error>() {
if e.kind() == io::ErrorKind::ConnectionAborted {
continue;
}
}
Err(e)?
}
}
}
}
}
Expand Down Expand Up @@ -65,7 +79,7 @@ where
}

SelectOutput::Err(e) => {
tracing::debug!(message = "Accept loop error.", error = %e);
tracing::debug!(error = %e, "accept loop error");
}

SelectOutput::Done => {
Expand Down
19 changes: 19 additions & 0 deletions tonic/src/transport/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub struct Server<L = Identity> {
http2_keepalive_timeout: Option<Duration>,
http2_adaptive_window: Option<bool>,
http2_max_pending_accept_reset_streams: Option<usize>,
http2_max_header_list_size: Option<u32>,
max_frame_size: Option<u32>,
accept_http1: bool,
service_builder: ServiceBuilder<L>,
Expand All @@ -117,6 +118,7 @@ impl Default for Server<Identity> {
http2_keepalive_timeout: None,
http2_adaptive_window: None,
http2_max_pending_accept_reset_streams: None,
http2_max_header_list_size: None,
max_frame_size: None,
accept_http1: false,
service_builder: Default::default(),
Expand Down Expand Up @@ -313,6 +315,17 @@ impl<L> Server<L> {
}
}

/// Sets the max size of received header frames.
///
/// This will default to whatever the default in hyper is. As of v1.4.1, it is 16 KiB.
#[must_use]
pub fn http2_max_header_list_size(self, max: impl Into<Option<u32>>) -> Self {
Server {
http2_max_header_list_size: max.into(),
..self
}
}

/// Sets the maximum frame size to use for HTTP2.
///
/// Passing `None` will do nothing.
Expand Down Expand Up @@ -482,6 +495,7 @@ impl<L> Server<L> {
http2_keepalive_timeout: self.http2_keepalive_timeout,
http2_adaptive_window: self.http2_adaptive_window,
http2_max_pending_accept_reset_streams: self.http2_max_pending_accept_reset_streams,
http2_max_header_list_size: self.http2_max_header_list_size,
max_frame_size: self.max_frame_size,
accept_http1: self.accept_http1,
}
Expand Down Expand Up @@ -514,6 +528,7 @@ impl<L> Server<L> {
let init_stream_window_size = self.init_stream_window_size;
let max_concurrent_streams = self.max_concurrent_streams;
let timeout = self.timeout;
let max_header_list_size = self.http2_max_header_list_size;
let max_frame_size = self.max_frame_size;
let http2_only = !self.accept_http1;

Expand Down Expand Up @@ -558,6 +573,10 @@ impl<L> Server<L> {
.max_pending_accept_reset_streams(http2_max_pending_accept_reset_streams)
.max_frame_size(max_frame_size);

if let Some(max_header_list_size) = max_header_list_size {
builder.http2().max_header_list_size(max_header_list_size);
}

builder
};

Expand Down

0 comments on commit 74a42fb

Please sign in to comment.