Open elvizlai opened 3 years ago
example code:
package main import ( "fmt" "net" "os" "os/signal" "syscall" "time" "github.com/soheilhy/cmux" "google.golang.org/grpc" ) func main() { lis, err := net.Listen("tcp", ":8080") if err != nil { panic(err) } mux := cmux.New(lis) grpcL := mux.Match(cmux.HTTP2HeaderField("content-type", "application/grpc")) _ = grpcL s := grpc.NewServer() // xxx.RegisterXXXServiceServer(s, XXXIMPL) go func() { // FIXME: using muxed grpcL here can not graceful stop err = s.Serve(lis) fmt.Println(err) }() fmt.Println("wait for sig") c := make(chan os.Signal, 1) signal.Notify(c, []os.Signal{syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGINT}...) <-c // FIXME: hangs on when start server with grpcL s.GracefulStop() fmt.Println("stopped") time.Sleep(time.Second * 1) }
See https://github.com/soheilhy/cmux/issues/76
example code: