sirupsen / logrus

Structured, pluggable logging for Go.
MIT License
24.3k stars 2.26k forks source link

How should I position my problem? #1414

Closed cnzackliu closed 4 months ago

cnzackliu commented 6 months ago

The service unexpectedly restarted last night. I can't find the cause of the problem. How should I position my problem?

// /home/jenkins/agent/workspace/bill/middleware/log.go:44
func (f *CustomFormatter) Format(entry *log.Entry) ([]byte, error) {
    var b *bytes.Buffer
    if entry.Buffer != nil {
        b = entry.Buffer
    } else {
        b = &bytes.Buffer{}
    }

    timestamp := entry.Time.Format("2006-01-02 15:04:05")
    newLog := fmt.Sprintf("[%s] [%s] [%s] - %s - %s \n", timestamp, strings.ToUpper(entry.Level.String()), f.TraceID, f.UserID, entry.Message) // line 44

    b.WriteString(newLog)
    return b.Bytes(), nil
}

// /home/jenkins/agent/workspace/bill/utility/request/request.go:153
func GetInner(url string, inf interface{}) error {
    log.Infof("request - get - %s ", url)
    resp, err := http.Get(url)
    if err != nil {
        log.Errorf("request - get - %s - Get fail: %s ", url, err.Error())
        return err
    }

    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        log.Errorf("request - get - %d - %s - ReadAll fail: %s ", resp.StatusCode, url, err.Error())
        return err
    }

    if resp.StatusCode != http.StatusOK {
        errMsg := map[string]string{}
        _ = jsoniter.Unmarshal(body, &errMsg)
        log.Errorf("response - get - %d - %s - success - %s ", resp.StatusCode, url, string(body))
        return fmt.Errorf(errMsg["msg"])
    }

    err = jsoniter.Unmarshal(body, inf)
    if err != nil {
        log.Errorf("request - get - %s - Unmarshal fail: %s ", url, err.Error())
        return err
    }

    log.Infof("response - get - %d - %s - success - %s ", resp.StatusCode, url, string(body)) // line 153
    return nil
}

// /home/jenkins/agent/workspace/bill/services/billing/au.go:17 
func GetUserInfo(token string) (modules.LoginPayload, error) {
    resp := GetUserInfoResp{}
    err := request.GetInner(fmt.Sprintf(BillingUserInfo+"?token=%s", token), &resp) // line 17
    return resp.Data, err
}

// /home/jenkins/agent/workspace/bill/router/authorization.go:59
func authorizationV2(c *gin.Context) {
    token := c.Query("token")
    rspacePayload, err := billing.GetUserInfo(token) // line 59
    if err != nil {
        c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"msg": err.Error()})
        return
    }

    c.Set("token", &rspacePayload)
    c.Next()
}

unexpected fault address 0x2d5e000 fatal error: fault [signal SIGSEGV: segmentation violation code=0x1 addr=0x2d5e000 pc=0x46aa39]

goroutine 12203 [running]: runtime.throw({0x1097cde?, 0xc000570bfe?}) /usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0xc002306e78 sp=0xc002306e48 pc=0x43849d runtime.sigpanic() /usr/local/go/src/runtime/signal_unix.go:846 +0x2c5 fp=0xc002306ec8 sp=0xc002306e78 pc=0x44e3a5 runtime.memmove() /usr/local/go/src/runtime/memmove_amd64.s:427 +0x4f9 fp=0xc002306ed0 sp=0xc002306ec8 pc=0x46aa39 fmt.(buffer).writeString(...) /usr/local/go/src/fmt/print.go:82 fmt.(fmt).padString(0x8?, {0x1337500, 0xc000570be0}) /usr/local/go/src/fmt/format.go:110 +0x247 fp=0xc002306f40 sp=0xc002306ed0 pc=0x4e65c7 fmt.(fmt).fmtS(0x10?, {0x1337500?, 0x40?}) /usr/local/go/src/fmt/format.go:359 +0x3f fp=0xc002306f78 sp=0xc002306f40 pc=0x4e713f fmt.(pp).fmtString(0x7f250267eb68?, {0x1337500?, 0x7f2529b2c108?}, 0x20?) /usr/local/go/src/fmt/print.go:477 +0xc5 fp=0xc002306fc8 sp=0xc002306f78 pc=0x4e9f85 fmt.(pp).printArg(0xc0027520d0, {0xee68e0?, 0xc0026256c0}, 0x73) /usr/local/go/src/fmt/print.go:725 +0x21e fp=0xc002307068 sp=0xc002306fc8 pc=0x4ebb1e fmt.(pp).doPrintf(0xc0027520d0, {0x10c515e, 0x1a}, {0xc002307230?, 0x5, 0x5}) /usr/local/go/src/fmt/print.go:1057 +0x288 fp=0xc002307160 sp=0xc002307068 pc=0x4eea88 fmt.Sprintf({0x10c515e, 0x1a}, {0xc002307230, 0x5, 0x5}) /usr/local/go/src/fmt/print.go:219 +0x59 fp=0xc0023071b8 sp=0xc002307160 pc=0x4e8c19 bill/middleware.(CustomFormatter).Format(0xc000570c00, 0xc0003e5570) /home/jenkins/agent/workspace/bill/middleware/log.go:44 +0x1e5 fp=0xc002307290 sp=0xc0023071b8 pc=0xd22b05 github.com/sirupsen/logrus.(Entry).write(0xc0003e5570) /go/pkg/mod/github.com/sirupsen/logrus@v1.8.1/entry.go:279 +0x56 fp=0xc002307320 sp=0xc002307290 pc=0xaaeef6 github.com/sirupsen/logrus.(Entry).log(0xc000352070, 0x4, {0xc002401900, 0x4de}) /go/pkg/mod/github.com/sirupsen/logrus@v1.8.1/entry.go:251 +0x3f9 fp=0xc002307408 sp=0xc002307320 pc=0xaaeaf9 github.com/sirupsen/logrus.(Entry).Log(0xc000352070, 0x4, {0xc002307460?, 0x3?, 0x3?}) /go/pkg/mod/github.com/sirupsen/logrus@v1.8.1/entry.go:293 +0x4f fp=0xc002307438 sp=0xc002307408 pc=0xaaf14f github.com/sirupsen/logrus.(Entry).Logf(0xc000352070, 0x4, {0x10d8a61?, 0xc0023074c0?}, {0xc0023075e8?, 0x10?, 0xee66e0?}) /go/pkg/mod/github.com/sirupsen/logrus@v1.8.1/entry.go:338 +0x85 fp=0xc002307480 sp=0xc002307438 pc=0xaaf6a5 github.com/sirupsen/logrus.(Logger).Logf(0xc00033a230, 0x4, {0x10d8a61, 0x28}, {0xc0023075e8, 0x3, 0x3}) /go/pkg/mod/github.com/sirupsen/logrus@v1.8.1/logger.go:151 +0x85 fp=0xc0023074d0 sp=0xc002307480 pc=0xab1ba5 github.com/sirupsen/logrus.(Logger).Infof(...) /go/pkg/mod/github.com/sirupsen/logrus@v1.8.1/logger.go:165 github.com/sirupsen/logrus.Infof(...) /go/pkg/mod/github.com/sirupsen/logrus@v1.8.1/exported.go:199 bill/utility/request.GetInner({0xc0021b09c0, 0x5d}, {0xec4a20, 0xc000637540}) /home/jenkins/agent/workspace/bill/utility/request/request.go:153 +0x554 fp=0xc002307690 sp=0xc0023074d0 pc=0xd225f4 bill/services/billing.GetUserInfo({0xc0021b0865, 0x24}) /home/jenkins/agent/workspace/bill/services/billing/au.go:17 +0xd7 fp=0xc002307700 sp=0xc002307690 pc=0xd9a777 bill/router.authorizationV2(0xc00025a900) /home/jenkins/agent/workspace/bill/router/authorization.go:59 +0xa8 fp=0xc002307888 sp=0xc002307700 pc=0xe46cc8 github.com/gin-gonic/gin.(Context).Next(...) /go/pkg/mod/github.com/gin-gonic/gin@v1.7.7/context.go:168 github.com/gin-gonic/gin.CustomRecoveryWithWriter.func1(0xc00025a900) /go/pkg/mod/github.com/gin-gonic/gin@v1.7.7/recovery.go:99 +0x82 fp=0xc0023078d8 sp=0xc002307888 pc=0xa5c262 github.com/gin-gonic/gin.(Context).Next(...) /go/pkg/mod/github.com/gin-gonic/gin@v1.7.7/context.go:168 github.com/gin-gonic/gin.(Engine).handleHTTPRequest(0xc000602340, 0xc00025a900) /go/pkg/mod/github.com/gin-gonic/gin@v1.7.7/gin.go:555 +0x7a2 fp=0xc002307a88 sp=0xc0023078d8 pc=0xa5b0a2 github.com/gin-gonic/gin.(Engine).ServeHTTP(0xc000602340, {0x133e7b0?, 0xc0026ad7a0}, 0xc002af2000) /go/pkg/mod/github.com/gin-gonic/gin@v1.7.7/gin.go:511 +0x1d2 fp=0xc002307ac8 sp=0xc002307a88 pc=0xa5a712 net/http.serverHandler.ServeHTTP({0x133c260?}, {0x133e7b0, 0xc0026ad7a0}, 0xc002af2000) /usr/local/go/src/net/http/server.go:2947 +0x30c fp=0xc002307b78 sp=0xc002307ac8 pc=0x7f532c net/http.(conn).serve(0xc000637400, {0x133f678, 0xc000437560}) /usr/local/go/src/net/http/server.go:1991 +0x607 fp=0xc002307fb8 sp=0xc002307b78 pc=0x7f03c7 net/http.(Server).Serve.func3() /usr/local/go/src/net/http/server.go:3102 +0x2e fp=0xc002307fe0 sp=0xc002307fb8 pc=0x7f5c6e runtime.goexit() /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc002307fe8 sp=0xc002307fe0 pc=0x469681 created by net/http.(Server).Serve /usr/local/go/src/net/http/server.go:3102 +0x4db

github-actions[bot] commented 5 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 4 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.