gogf / gf

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
https://goframe.org
MIT License
11.69k stars 1.59k forks source link

The data returned by the rpc call is nil, causing a panic, and then the system prints out a large number of 404 logs #2932

Open will0306 opened 1 year ago

will0306 commented 1 year ago

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的请求日志

2023-09-05 09:47:32.042 {f343d3bcdcb1a9fa5d298827a0f85c8d} 200 "GET http localhost:8000 /query?uid=810003599 HTTP/1.1" 0.028, ::1, "", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36", 14, "", ""
Stack:
1. last connection error: connection error: desc = "error reading server preface: http2: frame too large"
   1).  github.com/gogf/gf/contrib/rpc/grpcx/v2.modClient.UnaryError
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/contrib/rpc/grpcx/v2@v2.5.2/grpcx_interceptor_client.go:29
   2).  google.golang.org/grpc.getChainUnaryInvoker.func1
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/google.golang.org/grpc@v1.57.0/clientconn.go:508
   3).  github.com/gogf/gf/contrib/rpc/grpcx/v2/internal/tracing.UnaryClientInterceptor
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/contrib/rpc/grpcx/v2@v2.5.2/internal/tracing/tracing_interceptor_client.go:70
   4).  github.com/gogf/gf/contrib/rpc/grpcx/v2.modClient.UnaryTracing
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/contrib/rpc/grpcx/v2@v2.5.2/grpcx_interceptor_client.go:41
   5).  google.golang.org/grpc.chainUnaryClientInterceptors.func1
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/google.golang.org/grpc@v1.57.0/clientconn.go:496
   6).  google.golang.org/grpc.(*ClientConn).Invoke
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/google.golang.org/grpc@v1.57.0/call.go:40
   7).  helloworld/api/info/v1.(*infoClient).Query
        /tmp/code/helloworld/api/info/v1/info_grpc.pb.go:42
   8).  helloworld/internal/controller/user.(*ControllerV1).Query
        /tmp/code/helloworld/internal/controller/user/user_v1_query.go:19
   9).  github.com/gogf/gf/v2/net/ghttp.(*middleware).callHandlerFunc.func1
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/v2@v2.5.2/net/ghttp/ghttp_request_middleware.go:153
   10). github.com/gogf/gf/v2/net/ghttp.niceCallFunc
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/v2@v2.5.2/net/ghttp/ghttp_func.go:61
   11). github.com/gogf/gf/v2/net/ghttp.(*middleware).callHandlerFunc
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/v2@v2.5.2/net/ghttp/ghttp_request_middleware.go:130
   12). github.com/gogf/gf/v2/net/ghttp.(*middleware).Next.func1
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/v2@v2.5.2/net/ghttp/ghttp_request_middleware.go:76
   13). github.com/gogf/gf/v2/util/gutil.TryCatch
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/v2@v2.5.2/util/gutil/gutil.go:57
   14). github.com/gogf/gf/v2/net/ghttp.(*middleware).Next
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/v2@v2.5.2/net/ghttp/ghttp_request_middleware.go:50
   15). github.com/gogf/gf/v2/net/ghttp.MiddlewareHandlerResponse
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/v2@v2.5.2/net/ghttp/ghttp_middleware_handler_response.go:25
   16). github.com/gogf/gf/v2/net/ghttp.(*middleware).Next.func1.1
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/v2@v2.5.2/net/ghttp/ghttp_request_middleware.go:56
   17). github.com/gogf/gf/v2/net/ghttp.(*middleware).Next.func1
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/v2@v2.5.2/net/ghttp/ghttp_request_middleware.go:55
   18). github.com/gogf/gf/v2/net/ghttp.internalMiddlewareServerTracing
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/v2@v2.5.2/net/ghttp/ghttp_middleware_tracing.go:103
   19). github.com/gogf/gf/v2/net/ghttp.(*middleware).Next.func1.5
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/v2@v2.5.2/net/ghttp/ghttp_request_middleware.go:97
   20). github.com/gogf/gf/v2/net/ghttp.(*middleware).Next.func1
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/v2@v2.5.2/net/ghttp/ghttp_request_middleware.go:96
   21). github.com/gogf/gf/v2/net/ghttp.(*Server).ServeHTTP
        /Users/apple/.gvm/pkgsets/go1.18.10/global/pkg/mod/github.com/gogf/gf/v2@v2.5.2/net/ghttp/ghttp_server_handler.go:132

2023-09-05 09:47:32.043 {f343d3bcdcb1a9fa5d298827a0f85c8d} 200 "GET http localhost:8000 /query?uid=810003599 HTTP/1.1" 0.028, ::1, "", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
2023-09-05 09:47:32.043 {6bbdcfae7aaa9c32ea6e6e3b000de755} 404 "PRI http  * HTTP/2.0" 0.000, 192.168.100.145, "", ""
2023-09-05 09:47:33.046 {f8ef8a6d48c2b4e684cf53e82073fea2} 404 "PRI http  * HTTP/2.0" 0.000, 192.168.100.145, "", ""
2023-09-05 09:47:34.537 {af8fe0a63ce41fc39543c350da62d9b2} 404 "PRI http  * HTTP/2.0" 0.001, 192.168.100.145, "", ""
2023-09-05 09:47:37.295 {851724fdfb196af94f2145813f499477} 404 "PRI http  * HTTP/2.0" 0.001, 192.168.100.145, "", ""
2023-09-05 09:47:42.004 {4bb4a03d8c8caea546720607ae3709e6} 404 "PRI http  * HTTP/2.0" 0.001, 192.168.100.145, "", ""

5. What did you expect to see?

6. What did you see instead?

oldme-git commented 1 year ago

Can you show your code?

will0306 commented 1 year ago

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

will0306 commented 1 year ago

我请求了个不存在的id查询,如果没用注册服务发现,单机运行的情况下不会出现404,但是引入了etcd做分布式部署的情况下,,就会一直出现404

Issues-translate-bot commented 1 year ago

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.

gqcn commented 1 year ago

Let me see.

gqcn commented 1 year ago

@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, "", ""
gqcn commented 1 year ago

@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.

image
gqcn commented 1 year ago

We can add extra validation for server configuration keys to avoid this issue. Mark this as enhancement.

github-actions[bot] commented 1 year ago

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。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。