cloudwego / kitex

Go RPC framework with high-performance and strong-extensibility for building micro-services.
https://www.cloudwego.io
Apache License 2.0
6.92k stars 806 forks source link

官方 hello 示例,client 无法通过 GRPC 访问 #1496

Open kinnylee opened 3 weeks ago

kinnylee commented 3 weeks ago

Describe the bug 官方文档提供的最基础示例,直接访问没有问题。但是使用 GPRC 协议就会报错。 https://github.com/cloudwego/kitex-examples/blob/main/hello/client/main.go#L29 这行代码新增: client.WithTransportProtocol(transport.GRPC)。

启动服务端和客户端,报错:

Got a connection, launched process /Users/admin/Library/Caches/JetBrains/GoLand2023.3/tmp/GoLand/___go_build_github_com_cloudwego_kitex_examples_hello (pid = 2539). WARNING: undefined behavior - version of Delve is too old for Go version go1.22.5 (maximum supported version 1.21) WARNING:(encoder) sonic only supports Go1.16~1.22 && CPU amd64, but your environment is not suitable 2024/08/19 15:23:50.651378 server.go:83: [Info] KITEX: server listen at addr=[::]:8888 2024/08/19 15:24:13.645128 server_handler.go:326: [Error] KITEX: processing gRPC request error, remoteAddr=127.0.0.1:57267, error=panic: [happened in biz handler, method=Hello.echo, please check the panic at the server side] interface conversion: interface {} is streaming.Args, not api.HelloEchoArgs stack=goroutine 8 [running]: runtime/debug.Stack() /Users/admin/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/runtime/debug/stack.go:24 +0x64 github.com/cloudwego/kitex/server.(server).invokeHandleEndpoint.func1.1() /Users/admin/go/pkg/mod/github.com/cloudwego/kitex@v0.10.3/server/server.go:320 +0x1bc panic({0x105468ba0?, 0x140003eb3b0?}) /Users/admin/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/runtime/panic.go:770 +0xf0 github.com/cloudwego/kitex-examples/hello/kitex_gen/api/hello.echoHandler({0x105520bc0, 0x140003eb380}, {0x105450740, 0x1059c7f80}, {0x10540fce0, 0x14000020650}, {0x0, 0x0}) /Users/admin/bingx/code/cloud-native/共存验证/kitex/kitex-examples/hello/kitex_gen/api/hello/hello.go:39 +0x1b4 github.com/cloudwego/kitex/server.(server).invokeHandleEndpoint.func1({0x105520bc0, 0x140003eb380}, {0x10540fce0, 0x14000020650}, {0x0, 0x0}) /Users/admin/go/pkg/mod/github.com/cloudwego/kitex@v0.10.3/server/server.go:332 +0x64c github.com/cloudwego/kitex/pkg/remote/trans/nphttp2.(svrTransHandler).OnRead.func1.1() /Users/admin/go/pkg/mod/github.com/cloudwego/kitex@v0.10.3/pkg/remote/trans/nphttp2/server_handler.go:229 +0xd18 github.com/cloudwego/kitex/pkg/gofunc.init.0.func1.1() /Users/admin/go/pkg/mod/github.com/cloudwego/kitex@v0.10.3/pkg/gofunc/go.go:40 +0x48 github.com/bytedance/gopkg/util/gopool.(worker).run.func1.1(0x140001501c8, 0x14000062560) /Users/admin/go/pkg/mod/github.com/bytedance/gopkg@v0.0.0-20240514070511-01b2cbcf35e1/util/gopool/worker.go:69 +0xd4 github.com/bytedance/gopkg/util/gopool.(worker).run.func1() /Users/admin/go/pkg/mod/github.com/bytedance/gopkg@v0.0.0-20240514070511-01b2cbcf35e1/util/gopool/worker.go:70 +0x164 created by github.com/bytedance/gopkg/util/gopool.(worker).run in goroutine 52 /Users/admin/go/pkg/mod/github.com/bytedance/gopkg@v0.0.0-20240514070511-01b2cbcf35e1/util/gopool/worker.go:41 +0x78

To Reproduce

Steps to reproduce the behavior: 按照 https://www.cloudwego.io/zh/docs/kitex/getting-started/quick_start/ 这个文档操作 的

  1. cd kitex/kitex-examples/hello/
  2. 启动服务端:go run .
  3. 启动客户端:go run ./client 此时服务正常
  4. 修改 hello/client/main.go 代码,新增 client.WithTransportProtocol(transport.GRPC)
  5. 启动客户端:go run ./client 此时服务报错

Expected behavior

期望客户端能正确响应类似如下的信息 2024/08/19 15:32:28 Response({Message:test}) 2024/08/19 15:32:29 Response({Message:test}) 2024/08/19 15:32:30 Response({Message:test})

Screenshots

If applicable, add screenshots to help explain your problem.

Kitex version:

commit 9c40238d360052d6366842ee0701d195b08108b0

Environment:

GO111MODULE='on' GOARCH='arm64' GOBIN='' GOCACHE='/Users/admin/Library/Caches/go-build' GOENV='/Users/admin/Library/Application Support/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='arm64' GOHOSTOS='darwin' GOINSECURE='' GOMODCACHE='/Users/admin/go/pkg/mod' GONOPROXY='gitlab' GONOSUMDB='gitlab' GOOS='darwin' GOPATH='/Users/admin/go' GOPRIVATE='gitlab*' GOPROXY='https://goproxy.cn,direct' GOROOT='/Users/admin/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/Users/admin/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/pkg/tool/darwin_arm64' GOVCS='' GOVERSION='go1.22.5' GCCGO='gccgo' AR='ar' CC='clang' CXX='clang++' CGO_ENABLED='1' GOMOD='/........./kitex/kitex-examples/go.mod' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/44/g0pds8gx77z5cbfg90r9wb840000gn/T/go-build3520237026=/tmp/go-build -gno-record-gcc-switches -fno-common'

Additional context

Add any other context about the problem here.

YangruiEmma commented 3 weeks ago

Thrift over streaming 是今年支持的特性,hello 包里旧版本工具生成的代码不支持 Thrift streaming。如果你是为了测试 Thrift over grpc,可以用 https://github.com/cloudwego/kitex-examples/tree/main/thrift_streaming 的例子

YangruiEmma commented 3 weeks ago

或者你在本地更新下hello包下的生成代码就可以跑了,如果愿意更新生成代码后可以给 kitex-example 提个pr

kinnylee commented 3 weeks ago

公司已经用老的 kitex 版本,历史遗留的是没有 streaming 的能力的,怎么在现有的 hello demo 示例中去掉 streaming 能力来验证。

YangruiEmma commented 3 weeks ago

「怎么在现有的 hello demo 示例中去掉 streaming 能力来验证」那个demo就没有streaming的能力啊,你是想用streaming还是不想用。

另外,你们是哪个企业啊,有和我们对接过吗

GuangmingLuo commented 3 weeks ago

公司已经用老的 kitex 版本,历史遗留的是没有 streaming 的能力的,怎么在现有的 hello demo 示例中去掉 streaming 能力来验证。

我也没太理解你的诉求,企业用户可以先通过飞书群联系我 @kinnylee

ahaostudy commented 3 weeks ago

看着好像只是协议设置错误?这个example的生成代码是通过thrift idl生成的,本身就不支持改成grpc协议,如果需要使用grpc,可以编写一个proto idl来生成grpc版本的代码

kinnylee commented 3 weeks ago

公司已经用老的 kitex 版本,历史遗留的是没有 streaming 的能力的,怎么在现有的 hello demo 示例中去掉 streaming 能力来验证。

我也没太理解你的诉求,企业用户可以先通过飞书群联系我 @kinnylee

公司目前使用老版本的、不带 straming 能力的 kitex。以前部署在物理机上,一起正常。 现在要迁移到容器环境,入口网关使用 istio。从物理机往容器迁移的过程中,由于 istio 对 thrift 支持不好,因此请求报错。 我看网上的资料是按照这个 isssue 最开始我提到的方式修改,但是修改后本地 debug 都运行不了。大概是这样的情况哈。

kinnylee commented 3 weeks ago

看着好像只是协议设置错误?这个example的生成代码是通过thrift idl生成的,本身就不支持改成grpc协议,如果需要使用grpc,可以编写一个proto idl来生成grpc版本的代码

是要解决 k8s 环境下 istio 作为入口网关,无法正常代理的问题,按照 kitex examle istio 的示例,新增了这一行代码的。 由于历史原因,可能无法对存量代码全部改为 grpc,还是保持 thrift。

YangruiEmma commented 3 weeks ago

你新增的代码表示流量走http2协议,你问题重点在你们网关支持代理的协议是啥。 另外,如果是企业用户可以联系 @GuangmingLuo

kinnylee commented 3 weeks ago

你新增的代码表示流量走http2协议,你问题重点在你们网关支持代理的协议是啥。 另外,如果是企业用户可以联系 @GuangmingLuo

hello 那个示例给的是 thrift 协议的示例,也就是不能简单的新增 GPRC,只能针对 grpc 协议的新增这个配置吧。istio 网关支持 grpc,但是对 thrift 支持不是很好。

YangruiEmma commented 3 weeks ago

hello 那个示例给的是 thrift 协议的示例,也就是不能简单的新增 GPRC,只能针对 grpc 协议的新增这个配置吧。istio 网关支持 grpc,但是对 thrift 支持不是很好。

上面已经回复过了,Thrift over streaming 是今年支持的特性,这个demo比较早生成代码没更新

你在本地更新下hello包下的生成代码就可以跑了

现在streaming默认用http2协议,和grpc规范一样,但序列化用Thrift,如果你用envoy做代理,支持http2,理论是可以通的

kinnylee commented 2 weeks ago

本地更新下hello包下的生成代码

感谢回复,已验证 envoy 可以代理。

DMwangnima commented 2 weeks ago

@kinnylee 这个 issue 应该可以 close 了?另外有兴趣给我们的 sample 提 pr 么?