From 31381423cda6c322f35d78e9a656c8ebe078b0b1 Mon Sep 17 00:00:00 2001 From: Jayden Teoh Date: Fri, 20 Oct 2023 02:13:26 +0800 Subject: [PATCH] revert changes to greeter server example --- dialoptions.go | 3 ++- examples/helloworld/greeter_server/main.go | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/dialoptions.go b/dialoptions.go index 4e3f728fb7c2..249c67a6ee94 100644 --- a/dialoptions.go +++ b/dialoptions.go @@ -415,7 +415,8 @@ func WithTimeout(d time.Duration) DialOption { // should try to reconnect to the network address. // // Note: Go overrides the OS defaults for TCP keepalive time and interval to 15s. -// To retain OS defaults, use a net.Dialer with the KeepAlive field set to a negative value. +// To retain OS defaults, use a net.Dialer with the KeepAlive field set to a +// negative value. func WithContextDialer(f func(context.Context, string) (net.Conn, error)) DialOption { return newFuncDialOption(func(o *dialOptions) { o.copts.Dialer = f diff --git a/examples/helloworld/greeter_server/main.go b/examples/helloworld/greeter_server/main.go index 08b623d93300..7a62a9b9ff25 100644 --- a/examples/helloworld/greeter_server/main.go +++ b/examples/helloworld/greeter_server/main.go @@ -25,7 +25,6 @@ import ( "fmt" "log" "net" - "time" "google.golang.org/grpc" pb "google.golang.org/grpc/examples/helloworld/helloworld" @@ -48,9 +47,7 @@ func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloRe func main() { flag.Parse() - // Setting KeepAlive to -1 allows the listener to retain OS default TCP keepalive time and interval. - lc := net.ListenConfig{KeepAlive: time.Duration(-1)} - lis, err := lc.Listen(context.Background(), "tcp", fmt.Sprintf(":%d", *port)) + lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) if err != nil { log.Fatalf("failed to listen: %v", err) }