Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [Bug]: When it starts for a period of time, it indicates that the null pointer is abnormal, and the system is shut down. #2607

Closed
3 tasks done
biuaxia opened this issue Aug 28, 2023 · 2 comments

Comments

@biuaxia
Copy link

biuaxia commented Aug 28, 2023

Bug Description

You need to keep requesting back-end interfaces, and problems will occur after a period of time.

This is the full log:

2023/08/28 16:46:06.223624 bootstrap.go:124: [Warn] {"error":{"code":502,"message":"Bad Gateway"},"errorMsg":"Bad Gateway","exception":{"path":"/","url":"/","ua":"","route":"/","ips":"","host":"","body":"{}","bytesSent":0,"queryParams":"","ip":"192.1.1.45","re
ferer":"","protocol":"http","port":"49794","bytesReceived":0,"resBody":null,"reqHeaders":{},"requestid":null}}
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x1422680]

goroutine 82 [running]:
github.com/gofiber/fiber/v2.(*Ctx).Request(...)
        C:/Users/Administrator/go/pkg/mod/github.com/gofiber/fiber/[email protected]/ctx.go:464
github.com/biuaxia/crawling_FLiNGTrainer/pkg/util.Lang(0xc0000dc000)
        D:/wlm/GolandProjects/crawling_FLiNGTrainer/pkg/util/acceptlanguage_web_util.go:15 +0x120
github.com/biuaxia/crawling_FLiNGTrainer/bootstrap.NewApplication.func5(0x860086?, {0x20bae7c, 0x2})
        D:/wlm/GolandProjects/crawling_FLiNGTrainer/bootstrap/bootstrap.go:193 +0x1d
github.com/gofiber/contrib/fiberi18n.GetMessage({0x1f9b840?, 0xc000377738?})
        C:/Users/Administrator/go/pkg/mod/github.com/gofiber/contrib/[email protected]/i18n.go:105 +0x75
github.com/gofiber/contrib/fiberi18n.MustGetMessage(...)
        C:/Users/Administrator/go/pkg/mod/github.com/gofiber/contrib/[email protected]/i18n.go:85
github.com/biuaxia/crawling_FLiNGTrainer/pkg/i18n.Msg({0x2076328, 0xf})
        D:/wlm/GolandProjects/crawling_FLiNGTrainer/pkg/i18n/i18n.go:10 +0x33
github.com/biuaxia/crawling_FLiNGTrainer/pkg/resp.(*Resp).Build(0xc000377950)
        D:/wlm/GolandProjects/crawling_FLiNGTrainer/pkg/resp/resp.go:75 +0x3b
github.com/biuaxia/crawling_FLiNGTrainer/bootstrap.NewApplication.func3(0xc0001e6c00, {0x2308140, 0xc00028cb70})
        D:/wlm/GolandProjects/crawling_FLiNGTrainer/bootstrap/bootstrap.go:140 +0xd8f
github.com/gofiber/fiber/v2.(*App).ErrorHandler(0xc000280d80, 0xc0001e6c00, {0x2308140, 0xc00028cb70})
        C:/Users/Administrator/go/pkg/mod/github.com/gofiber/fiber/[email protected]/app.go:1054 +0x1ff
github.com/gofiber/fiber/v2.(*App).serverErrorHandler(0xc000280d80, 0xc00070fc20?, {0x23087a0, 0xc000412050})
        C:/Users/Administrator/go/pkg/mod/github.com/gofiber/fiber/[email protected]/app.go:1086 +0x2fb
github.com/valyala/fasthttp.(*Server).writeErrorResponse(0xc000458200?, 0x0, 0xc000252600, {0x0, 0x0}, {0x23087a0?, 0xc000412050?})
        C:/Users/Administrator/go/pkg/mod/github.com/valyala/[email protected]/server.go:2856 +0x57
github.com/valyala/fasthttp.(*Server).serveConn(0xc000458200, {0x230e6f0?, 0xc000384030})
        C:/Users/Administrator/go/pkg/mod/github.com/valyala/[email protected]/server.go:2291 +0x1de5
github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc00045e3c0, 0xc00009c000)
        C:/Users/Administrator/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:224 +0xa4
github.com/valyala/fasthttp.(*workerPool).getCh.func1()
        C:/Users/Administrator/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:196 +0x32
created by github.com/valyala/fasthttp.(*workerPool).getCh in goroutine 34
        C:/Users/Administrator/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:195 +0x1ab

I am using our framework for the first time. Please help me analyze the possible causes of the problem and give me a solution if it is convenient.
Until then, I will try to solve it myself.

How to Reproduce

acceptlanguage_web_util.go:

package util

import (
	"strings"

	"github.com/gofiber/fiber/v2/log"
	"github.com/gofiber/fiber/v2"
)

func Lang(c *fiber.Ctx) string {
	for _, langFinalStr := range []string{
		"lang", "Lang", "LANG",
		"language", "Language", "LANGUAGE",
	} {
		log.Infof("pkg/util/acceptlanguage_web_util.go:15 => c: %#v, request: %#v, langFinalStr: %q", c, c.Request(), langFinalStr)
		langStr := c.Query(langFinalStr)
		if langStr != "" {
			return langStr
		}
	}

	lang := c.Get("Accept-Language")
	if lang != "" {
		var acceptLanguage string
		for _, l := range ParseAcceptLanguage(lang, []string{}) {
			if !strings.Contains(l, "-") {
				acceptLanguage = l
				break
			} else {
				index := strings.Index(l, "-")
				acceptLanguage = l[:index]
			}
		}
		return acceptLanguage
	}
	return "en"
}

Expected Behavior

Normal operation.

Fiber Version

v2.48.0

Code Snippet (optional)

Some of the code is the generation environment, if you need the code, please leave an email, I will send it to you by email.

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.
@welcome
Copy link

welcome bot commented Aug 28, 2023

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@ReneWerner87
Copy link
Member

ReneWerner87 commented Aug 28, 2023

panic is happening in the i18n contrib middleware
image

Duplicate of gofiber/contrib#721

we are on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants