gRPC cannot assign requested address

Suppose you just run into this exception, saying that gRPC cannot assign requested address: TL;DR: most likely you opened too many connections, and you run out of ephemeral ports. Consider channel/stub reuse: https://mchesnavsky.tech/grpc-channel-stub-reuse. Details: first, we should distinguish between fixed ports, and ephemeral ports. Ephemeral ports are typically used by client devices initiating communication with […]

READ MORE

gRPC channel / stub reuse

Creating new gRPC channels and stubs involves establishing connections and negotiating capabilities with the server. Reusing them eliminates this overhead for subsequent calls. By keeping connections alive, you avoid the initial handshake delay for each RPC, leading to faster communication. However, you should ensure that reusing the channel doesn’t create a bottleneck in your application. […]

READ MORE

gRPC transport and channel providers

Let’s discuss some details around that how gRPC manages transport providers. Remember, that we have two closely related concepts in gRPC: If you didn’t familiar with NameResolvers, I strongly encourage you to peruse previous part of our narrative here: https://mchesnavsky.tech/name-resolution-providers. This article will be about the latter. Alright, we should elaborate, that a gRPC channel […]

READ MORE

gRPC name resolution providers

We have something special today. It all started with that I updated grpc-java version from 1.43.2 to 1.60.0. Alright, I just updated dependency and anticipated it working. However, I run into exception on ManagedChannel build at the client side: Exception I got looks like this: Another modifications: If you’re looking for the simplest & quickest […]

READ MORE

gRPC Timeouts & Deadlines

First, let’s figure out how the timeout differs from the deadline. Timeout is relative value, but deadline is absolute. If we take a timeout and a deadline of 5 seconds, and we will write the following line (the code for an example, it will not work if you run it): Then, if you want to […]

READ MORE

gRPC channel for target was not shutdown properly

Imagine you are faced with an error like this: The point is that if you create a gRPC channel, you must close it after use. Let’s say you’ve already made a channel like this: After use, it will need to be closed. It is important to wait until it closes; awaitTermination() is used for this:

READ MORE

Using gRPC with JKS

gRPC doesn’t support JKS out of the box, but there is a workaround. Below is an example of how to use gRPC and JKS. Server side Client side If you don’t need to use custom truststore, you need to do nothing. If you need to use custom truststore, use example below: You can use trustManagerFactory […]

READ MORE

Cancelling gRPC server-streaming call from client

When using gRPC server-streaming call, you may need to interrupt the execution of the request on the server from the client side.  We have a service on the server: And the sendRequest() method on the client: Suppose, that at some moment we need to send a message from the client to the server that the […]

READ MORE