2

this one is weirdo and bugging me quite a bit. I'm learning gRPC with tonic & prost. I've followed a tutorial and basically wrote a simple voting server & client. Locally, it runs perfectly fine. Next, I dockerized the voting service, and only when the service runs inside docker, I get the following error:

Error: Status { code: Unknown, message: "transport error", source: Some(tonic::transport::Error(Transport, hyper::Error(Io, Kind(BrokenPipe)))) }

The service is quite basic, here the gist of it:

#[tonic::async_trait]
impl Voting for VotingService {
    async fn vote(&self, request: Request<VotingRequest>) -> Result<Response<VotingResponse>, Status> {
        let r = request.into_inner();
        match r.vote {
            0 => Ok(Response::new(voting::VotingResponse { confirmation: {
                format!("Happy to confirm that you upvoted for {}", r.url)
            }})),
            1 => Ok(Response::new(voting::VotingResponse { confirmation: {
                format!("Confirmation that you downvoted for {}", r.url)
            }})),
            _ => Err(Status::new(tonic::Code::OutOfRange, "Invalid vote provided"))
        }
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let server_details = "127.0.0.1:8080";
    let address: SocketAddr = server_details.parse().expect("Unable to parse socket address");

    let voting_service = VotingService::default();
    println!("Running voting service on port 8080");
    Server::builder().add_service(VotingServer::new(voting_service)).serve(address).await?;
    Ok(())
}

Full code

Things I have tried:

  1. Exact match of protoc version for client & server -> No impact.
  2. Replaced the distroless image with Debian Slim -> No impact.
  3. Googled the Kind(BrokenPipe) Error. Indicate the server would close connection. Why?

It's so strange that the connection close only happens in Docker. However, I'm just starting out learning Rust, so it might be very well that either the client or server contains some bugs that only show up under certain circumstances.

Any help would be appreciated.

Marvin.Hansen
  • 1,436
  • 1
  • 15
  • 29
  • 4
    In Docker, a server process needs to listen on the special 0.0.0.0 "all interfaces" address, or it will be unreachable from outside its container. See [Docker app server ip address 127.0.0.1 difference of 0.0.0.0 ip](https://stackoverflow.com/questions/59179831/docker-app-server-ip-address-127-0-0-1-difference-of-0-0-0-0-ip) for example. There will also be differences on the client side and [Networking in Compose](https://docs.docker.com/compose/networking/) might be a good starting point. – David Maze Aug 03 '22 at 10:00
  • Solved. It really was the IP address. Thank you @DavidMaze – Marvin.Hansen Aug 03 '22 at 10:25

0 Answers0