Skip to content

feat(grpc): Add tonic transport #2339

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

arjan-bal
Copy link
Contributor

This PR includes the following:

  1. A transport trait that will be used by gRPC subchannels. Transports are expected to transfer serialized messages as bytes, but an in-memory transport may also transfer structs without serialization.
  2. The runtime trait is extended to include a method for creating TCP streams. Adapters are added to convert a gRPC runtime to a Hyper runtime.
  3. A transport implementation that uses tonic. To avoid a dependency on the code in tonic/src/transport, required code is copied over.
  4. A tonic codec that sends/receives Bytes. This is a temporary workaround until tonic supports bypassing the codec and receiving bytes.
  5. A test that uses the grpc tonic transport to create a bi-di stream with a tonic server.

@arjan-bal arjan-bal force-pushed the grpc-tonic-transport-1 branch from 1417e9d to 66e6c10 Compare July 15, 2025 07:27
@arjan-bal
Copy link
Contributor Author

Hi @dfawley and @LucioFranco, could you please review this PR when you have a moment?

@arjan-bal arjan-bal force-pushed the grpc-tonic-transport-1 branch from fe1436e to 957377c Compare July 21, 2025 09:30
@@ -229,6 +235,7 @@ impl InternalSubchannel {
transport: Arc<dyn Transport>,
backoff: Arc<dyn Backoff>,
unregister_fn: Box<dyn FnOnce(SubchannelKey) + Send + Sync>,
runtime: Arc<dyn Runtime>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious:

Given that we will have the same runtime for all the different gRPC components that require a runtime, did we consider something like a singleton that is initialized at init time, and all the components can use a getter to retrieve and use the singleton instead of the runtime being passed to every component that needs it?

@@ -345,30 +353,34 @@ impl InternalSubchannel {
let transport = self.transport.clone();
let address = self.address().address;
let state_machine_tx = self.state_machine_event_sender.clone();
let connect_task = tokio::task::spawn(async move {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have some kind of vet equivalent to ensure that task spawning (and other features provided by the runtime) are always only used from the runtime and not from other places (like tokio or the standard library)?

self.m
.lock()
.unwrap()
.insert(address_type.to_string(), Arc::new(transport));
}

/// Retrieve a name resolver from the registry, or None if not found.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this comments needs updating.

@@ -26,20 +25,20 @@ impl std::fmt::Debug for TransportRegistry {

impl TransportRegistry {
/// Construct an empty name resolver registry.
pub fn new() -> Self {
pub(crate) fn new() -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also implement Default trait for this type by inheriting it?

@@ -388,7 +400,9 @@ impl InternalSubchannel {
// error string containing information about why the connection
// terminated? But what can we do with that error other than logging
// it, which the transport can do as well?
svc.disconnected().await;
if let Err(e) = closed_rx.await {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the above task spawn be on the runtime as well instead of directly using tokio?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants