Open will0306 opened 1 year ago
Can you show your code?
manifest/config/config.yaml
cat manifest/config/config.yaml
server:
address: ":8000"
openapiPath: "/api.json"
swaggerPath: "/swagger"
JagerAgentHost: "localhost:6831"
serverName: "http-demo"
readTimeout: "1s"
writeTimeout: "1s"
idleTimeout: "2s"
logPath: "/tmp/grpc-log/"
logStdout: true
errorStack: true
errorLogEnabled: true
errorLogPattern: "error-{Ymd}.log"
accessLogEnabled: true
accessLogPattern: "access-{Ymd}.log"
header: true
logger:
level : "all"
stdout: true
database:
default:
- link: "mysql:root:rootPassW0rd@tcp(192.168.100.1:3306)/bravo"
type: "mysql"
debug: true
http-server.go
package main
import (
"helloworld/internal/library/tracer"
_ "helloworld/internal/packed"
"github.com/gogf/gf/contrib/registry/etcd/v2"
"github.com/gogf/gf/contrib/rpc/grpcx/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/gsvc"
"github.com/gogf/gf/v2/os/gctx"
"helloworld/internal/cmd"
)
func main() {
rg := etcd.New("192.168.100.1:2379")
gsvc.SetRegistry(rg)
grpcx.Resolver.Register(etcd.New("192.168.100.1:2379"))
var (
ctx = gctx.GetInitCtx()
)
if err := tracer.Init(ctx, "http-server"); err != nil {
g.Log().Errorf(ctx, "init tracer failed, error: %s", err.Error())
}
defer tracer.Unregister(ctx)
cmd.Main.Run(ctx)
}
rpc-server.go
package main
import (
v1 "helloworld/internal/rpc/info/v1"
"helloworld/internal/library/tracer"
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
"github.com/gogf/gf/contrib/registry/etcd/v2"
"github.com/gogf/gf/contrib/rpc/grpcx/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/gsvc"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
rg := etcd.New("192.168.100.1:2379")
gsvc.SetRegistry(rg)
grpcx.Resolver.Register(etcd.New("192.168.100.1:2379"))
var (
ctx = gctx.GetInitCtx()
)
if err := tracer.Init(ctx, "rpc-server"); err != nil {
g.Log().Errorf(ctx, "init tracer failed, error: %s", err.Error())
}
defer tracer.Unregister(ctx)
s := grpcx.Server.New()
v1.Register(s)
s.Run()
}
其他文件你可以下载压缩文件,数据库文件也在里面了 code.tar.gz
我请求了个不存在的id查询,如果没用注册服务发现,单机运行的情况下不会出现404,但是引入了etcd做分布式部署的情况下,,就会一直出现404
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
I requested a non-existent id query. If the registration service is not used to find out, 404 will not appear in the case of stand-alone operation, but in the case of introducing etcd for distributed deployment, 404 will always appear.
Let me see.
@will0306 It is strange that, the logging content shows that some client wants to create http2 connection with http server but the http server does recognize the request method PRI
, as the http server does not support http2.
2023-09-05 09:47:32.043 {6bbdcfae7aaa9c32ea6e6e3b000de755} 404 "PRI http * HTTP/2.0" 0.000, 192.168.100.145, "", ""
@will0306 Hello, I figured out that you are using the same service name default
in both http
and grpc
server, which makes the grpc client from the http handler connects to the http
server address, so the http
server continues printing PRI *
errors to warn you the http
server does not support http2.
You can change the incorrect configuration item from serverName
to name
to correct the configuration for http server name, which can make the http
and grpc
the different names.
We can add extra validation for server configuration keys to avoid this issue. Mark this as enhancement.
Hello @will0306. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it! 你好 @will0306。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。
1. What version of
Go
and system type/arch are you using?go version go1.18.10 darwin/arm64
2. What version of
GoFrame
are you using?GoFrame CLI Tool v2.5.2, https://goframe.org GoFrame Version: v1.16.9 in current go.mod CLI Installed At: /Users/apple/workspace/gopath/bin/gf CLI Built Detail: Go Version: go1.20.6 GF Version: v2.5.2 Git Commit: 2023-08-18 09:57:25 cf299273c499aafb5d19829809dfb6b8ef280c12 Build Time: 2023-08-18 16:23:18
3. Can this issue be re-produced with the latest release?
yes
4. What did you do?
http 调用rpc,一个变量没做nil判断,导致了panic,然后一直有404的请求日志
5. What did you expect to see?
6. What did you see instead?