SkyAPM / go2sky

Distributed tracing and monitor SDK in Go for Apache SkyWalking APM
https://skywalking.apache.org/
Apache License 2.0
448 stars 122 forks source link

send keep alive signal error rpc error #159

Closed rysinal closed 2 years ago

rysinal commented 2 years ago

Describe the bug

first set env:

export SW_AGENT_COLLECTOR_BACKEND_SERVICES=10.0.x.x:11800
export SW_AGENT_NAME=mydemo
export SW_AGENT_INSTANCE=instancedemo

and this is my demo code:

        Router := gin.Default()
        rp, err := reporter.NewGRPCReporter("10.0.xx.xxx:11800", reporter.WithCheckInterval(time.Second))
        if err != nil {
            global.GVA_LOG.Error("new reporter error", zap.Error(err))
        }
        defer rp.Close()

        tracer, err := go2sky.NewTracer(os.Getenv("SW_AGENT_NAME"), go2sky.WithReporter(rp), go2sky.WithInstance(os.Getenv("SW_AGENT_INSTANCE")))
        if err != nil {
            global.GVA_LOG.Error("create tracer error", zap.Error(err))
        }
        Router.Use(v3.Middleware(Router, tracer))
    Router.GET("/user/:name", func(c *gin.Context) {
        name := c.Param("name")
        c.String(http.StatusOK, "Hello %s", name)
    })

    s := endless.NewServer(address, Router)
    s.ReadHeaderTimeout = 20 * time.Second
    s.WriteTimeout = 20 * time.Second
    s.MaxHeaderBytes = 1 << 20

i got an error message when my project start or access some api interface, and i can't see any message from skywalking-ui

go2sky-gRPC2022/05/27 19:15:04 send keep alive signal error rpc error: code = Canceled desc = grpc: the client connection is closing
[GIN] 2022/05/27 - 19:24:27 | 200 |     147.136µs |             ::1 | GET      "/user/lisi"
go2sky-gRPC2022/05/27 19:24:27 reporter segment err send on closed channel

To Reproduce Steps to reproduce the behavior:

Expected behavior can send trace message to the oap server

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

arugal commented 2 years ago

@rysinal It looks like GRPCReporter was closed early, please check your code :)

rysinal commented 2 years ago

@rysinal It looks like GRPCReporter was closed early, please check your code :)

@arugal I tested the following scenarios

func RunWindowsServer() {

    Router := initialize.Routers()

        // The code for skywalking is placed here,it's just record /user/:name ,but not initialize.Routers()
        rp, err := reporter.NewGRPCReporter("10.0.xx.xxx:11800", reporter.WithCheckInterval(time.Second))
        if err != nil {
            global.GVA_LOG.Error("new reporter error", zap.Error(err))
        }
        defer rp.Close()

        tracer, err := go2sky.NewTracer(os.Getenv("SW_AGENT_NAME"), go2sky.WithReporter(rp), go2sky.WithInstance(os.Getenv("SW_AGENT_INSTANCE")))
        if err != nil {
            global.GVA_LOG.Error("create tracer error", zap.Error(err))
        }
        Router.Use(v3.Middleware(Router, tracer))

    Router.GET("/user/:name", func(c *gin.Context) {
        name := c.Param("name")
        c.String(http.StatusOK, "Hello %s", name)
    })
        Router.Run(":8000")
}

1、This code will cause the initialize.Routers() method route above to not be injected into skywalking, but the /user/:name route at the bottom to be injected properly 2、When the code of skywalking is put into the initialize.Routers() function, it will report an error,

 send keep alive signal error rpc error: code = Unavailable desc = error reading from server: read tcp 10.85.xx.xx:64424->10.0.xx.xx:11800: use of closed network connection

Just like the following sample code

func Routers() *gin.Engine {
    Router := gin.Default()

        rp, err := reporter.NewGRPCReporter("10.0.xx.xxx:11800", reporter.WithCheckInterval(time.Second))
        if err != nil {
            global.GVA_LOG.Error("new reporter error", zap.Error(err))
        }
        defer rp.Close()

        tracer, err := go2sky.NewTracer(os.Getenv("SW_AGENT_NAME"), go2sky.WithReporter(rp), go2sky.WithInstance(os.Getenv("SW_AGENT_INSTANCE")))
        if err != nil {
            global.GVA_LOG.Error("create tracer error", zap.Error(err))
        }
        Router.Use(v3.Middleware(Router, tracer))

        Router.GET("/user/:name", func(c *gin.Context) {
        name := c.Param("name")
        c.String(http.StatusOK, "Hello %s", name)
    })
        return Router
}

I just started to learn golang, please help to see where the problem, thanks!:)

arugal commented 2 years ago
func Routers() *gin.Engine {
    Router := gin.Default()

        rp, err := reporter.NewGRPCReporter("10.0.xx.xxx:11800", reporter.WithCheckInterval(time.Second))
        if err != nil {
            global.GVA_LOG.Error("new reporter error", zap.Error(err))
        }
        defer rp.Close()

        tracer, err := go2sky.NewTracer(os.Getenv("SW_AGENT_NAME"), go2sky.WithReporter(rp), go2sky.WithInstance(os.Getenv("SW_AGENT_INSTANCE")))
        if err != nil {
            global.GVA_LOG.Error("create tracer error", zap.Error(err))
        }
        Router.Use(v3.Middleware(Router, tracer))

        Router.GET("/user/:name", func(c *gin.Context) {
        name := c.Param("name")
        c.String(http.StatusOK, "Hello %s", name)
    })
        return Router
}

Just like your code, GRPCReporter closed by defer rp.Close().