According to the gRPC documentation, [deadlines](http://www.grpc.io/docs/guides/concepts.html#deadlines) can be specified by clients to determine how long the client will wait on the server before exiting with a `DEADLINE_EXCEEDED` error. The documentation mentions that different languages have different implementations and that some languages do not have default values. 

Indeed, a quick CTRL+F for "deadline" on the [Go gRPC documentation](https://godoc.org/google.golang.org/grpc) reveals no results. What I did discover was a [`WithTimeout`](https://godoc.org/google.golang.org/grpc#WithTimeout) on the dialer for the TCP connection. 

Implemented as follows (from the [helloworld example](https://github.com/grpc/grpc-go/tree/master/examples/helloworld)): 

```
package main

import (
    "log"
    "os"
    "time"

    "golang.org/x/net/context"
    "google.golang.org/grpc"
    pb "google.golang.org/grpc/examples/helloworld/helloworld"
)

const (
    address     = "localhost:50051"
    defaultName = "world"
    deadline    = 20 
)

func main() {
    // Set up a connection to the server with a timeout 
    conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithTimeout(time.Duration(deadline)*time.Second)
    if err != nil {
        log.Fatalf("did not connect: %v", err)
    }
    defer conn.Close()
    c := pb.NewGreeterClient(conn)

    // Contact the server and print out its response.
    name := defaultName
    if len(os.Args) > 1 {
        name = os.Args[1]
    }
    r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: name})
    if err != nil {
        log.Fatalf("could not greet: %v", err)
    }
    log.Printf("Greeting: %s", r.Message)
}

```

The code will raise an error only if *the client cannot connect after 20 seconds*. The output will be something as follows: 

```
2016/05/24 09:02:54 grpc: Conn.resetTransport failed to create client transport: connection error: desc = "transport: dial tcp [::1]:3265: getsockopt: connection refused"; Reconnecting to "localhost:3265"
2016/05/24 09:02:54 Failed to dial localhost:3265: grpc: timed out trying to connect; please retry.
2016/05/24 09:02:54 could not greet: rpc error: code = 2 desc = grpc: the client connection is closing

```

As noted in the question title, the system I'm working with is peer to peer, so there is no central, always up server and therefore the retry system that gRPC implements is wonderful. However, I'm actually looking for deadlines because if the remote does connect, but the server takes > 20 seconds to respond, no exception will be raised in the `WithTimeout` context. 

A complete win for me would be a timeout/deadline system where:

* if the client cannot connect, an error is returned after timeout
* if the client connects, but the server doesn't respond before timeout, an error is returned.
* if the client connects, but the connection drops before timeout, an error is returned.

My feeling though is that I will need some combination of connection management plus gRPC deadline management. Does anyone know how to implement deadlines in Go?