Closed tran-the-lam closed 1 year ago
@Skyenought can you help here
let me see.
I will be making a pull request to fix the known issues
@Skyenought I got the code from master branch but when I run the request concurrently, the system still gives i18n error
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x13e3e79]
goroutine 173 [running]:
github.com/valyala/fasthttp.(*RequestCtx).URI(...)
/Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:952
github.com/valyala/fasthttp.(*RequestCtx).QueryArgs(0x0)
/Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:991 +0x19
github.com/gofiber/fiber/v2.(*Ctx).Query(0xc000402840, {0x1a3ee1f, 0x4}, {0x0, 0x0, 0x0?})
/Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/ctx.go:1054 +0x45
my-fiberi18n/pkg/i18n.defaultLangHandler(0xc000860086?, {0x1a80bae, 0x2})
@tran-the-lam show your code ?
had you read article -> https://docs.gofiber.io/#zero-allocation
@tran-the-lam show your code ?
You can see my demo(https://github.com/tran-the-lam/debug-fiberi18n)
Step 1: go run main.go
Step 2: . scripts/concurrent_request.sh
Error:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x135e679]
goroutine 10 [running]:
github.com/valyala/fasthttp.(*RequestCtx).URI(...)
/Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:952
github.com/valyala/fasthttp.(*RequestCtx).QueryArgs(0x0)
/Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:991 +0x19
github.com/gofiber/fiber/v2.(*Ctx).Query(0xc00020c000, {0x150c47b, 0x4}, {0x0, 0x0, 0x0?})
/Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/ctx.go:1054 +0x45
test/fiberi18n.defaultLangHandler(0xc000860086?, {0x152a6d4, 0x2})
/Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/fiberi18n/config.go:80 +0x3f
test/fiberi18n.GetMessage({0x1488ce0?, 0x15bf2b0?})
/Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/fiberi18n/i18n.go:105 +0x86
test/fiberi18n.MustGetMessage(...)
/Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/fiberi18n/i18n.go:85
main.main.func1(0xc0000e0840)
/Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/main.go:24 +0x6a
github.com/gofiber/fiber/v2.(*App).next(0xc000080d80, 0xc0000e0840)
/Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/router.go:144 +0x1bf
github.com/gofiber/fiber/v2.(*Ctx).Next(0xc0001de000?)
/Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/ctx.go:913 +0x53
test/fiberi18n.New.func1(0x14a5680?)
/Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/fiberi18n/i18n.go:25 +0x5e
github.com/gofiber/fiber/v2.(*App).next(0xc000080d80, 0xc0000e0840)
/Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/router.go:144 +0x1bf
github.com/gofiber/fiber/v2.(*App).handler(0xc000080d80, 0x10860f7?)
/Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/router.go:171 +0x87
github.com/valyala/fasthttp.(*Server).serveConn(0xc0001bc000, {0x15c5640?, 0xc00028c170})
/Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:2365 +0x11d3
github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc0000ccf00, 0xc0000720c0)
/Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/workerpool.go:224 +0xa9
github.com/valyala/fasthttp.(*workerPool).getCh.func1()
/Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/workerpool.go:196 +0x38
created by github.com/valyala/fasthttp.(*workerPool).getCh
/Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/workerpool.go:195 +0x1b0
exit status 2
here you should do a copy https://github.com/tran-the-lam/debug-fiberi18n/blob/main/fiberi18n/config.go#L85 because of our zero allocation concept -> read the article
here you should do a copy https://github.com/tran-the-lam/debug-fiberi18n/blob/main/fiberi18n/config.go#L85 because of our zero allocation concept -> read the article
I tried but response still same error My code:
lang = c.Get("Accept-Language")
buffer := make([]byte, len(lang))
copy(buffer, lang)
langRs := string(buffer)
if langRs != "" {
return langRs
}
Maybe gofiber/contrib/fiberi18n has the same problem https://github.com/gofiber/contrib/blob/2bad1b1d10b4f1bbc0196947feb679d0b8f81c9d/fiberi18n/config.go#L85
problem is that you store the value in a map which survives longer than the request response loop, so you should make a copy here with our copy function
@Skyenought same problem is here https://github.com/gofiber/contrib/blob/2bad1b1d10b4f1bbc0196947feb679d0b8f81c9d/fiberi18n/i18n.go#LL106C45-L106C49
we need better unittests
yes, i will
@tran-the-lam show your code ?
You can see my demo(https://github.com/tran-the-lam/debug-fiberi18n) Step 1: go run main.go Step 2:
. scripts/concurrent_request.sh
Error:panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x135e679] goroutine 10 [running]: github.com/valyala/fasthttp.(*RequestCtx).URI(...) /Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:952 github.com/valyala/fasthttp.(*RequestCtx).QueryArgs(0x0) /Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:991 +0x19 github.com/gofiber/fiber/v2.(*Ctx).Query(0xc00020c000, {0x150c47b, 0x4}, {0x0, 0x0, 0x0?}) /Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/ctx.go:1054 +0x45 test/fiberi18n.defaultLangHandler(0xc000860086?, {0x152a6d4, 0x2}) /Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/fiberi18n/config.go:80 +0x3f test/fiberi18n.GetMessage({0x1488ce0?, 0x15bf2b0?}) /Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/fiberi18n/i18n.go:105 +0x86 test/fiberi18n.MustGetMessage(...) /Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/fiberi18n/i18n.go:85 main.main.func1(0xc0000e0840) /Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/main.go:24 +0x6a github.com/gofiber/fiber/v2.(*App).next(0xc000080d80, 0xc0000e0840) /Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/router.go:144 +0x1bf github.com/gofiber/fiber/v2.(*Ctx).Next(0xc0001de000?) /Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/ctx.go:913 +0x53 test/fiberi18n.New.func1(0x14a5680?) /Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/fiberi18n/i18n.go:25 +0x5e github.com/gofiber/fiber/v2.(*App).next(0xc000080d80, 0xc0000e0840) /Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/router.go:144 +0x1bf github.com/gofiber/fiber/v2.(*App).handler(0xc000080d80, 0x10860f7?) /Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/router.go:171 +0x87 github.com/valyala/fasthttp.(*Server).serveConn(0xc0001bc000, {0x15c5640?, 0xc00028c170}) /Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:2365 +0x11d3 github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc0000ccf00, 0xc0000720c0) /Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/workerpool.go:224 +0xa9 github.com/valyala/fasthttp.(*workerPool).getCh.func1() /Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/workerpool.go:196 +0x38 created by github.com/valyala/fasthttp.(*workerPool).getCh /Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/workerpool.go:195 +0x1b0 exit status 2
In fact, although I didn't use methods like utils.CopyString()
, I didn't get a panic when I executed this script 🤔
In fact, I used ab
for the stress test, and there was no panic
> ab -n 1000 -c 50 http://127.0.0.1:3000/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software:
Server Hostname: 127.0.0.1
Server Port: 3000
Document Path: /
Document Length: 5 bytes
Concurrency Level: 50
Time taken for tests: 0.021 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 140000 bytes
HTML transferred: 5000 bytes
Requests per second: 46777.06 [#/sec] (mean)
Time per request: 1.069 [ms] (mean)
Time per request: 0.021 [ms] (mean, across all concurrent requests)
Transfer rate: 6395.30 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 1
Processing: 0 1 0.8 1 7
Waiting: 0 1 0.7 1 7
Total: 0 1 0.8 1 7
Percentage of the requests served within a certain time (ms)
50% 1
66% 1
75% 1
80% 1
90% 2
95% 3
98% 3
99% 3
100% 7 (longest request)
@Skyenought Is this line already in your source test?
@tran-the-lam ok, i will fix them
i think you can add recover to your code, after you do this you can run service success.
I don't know what it's about 😖
Recover link not found
@tran-the-lam show your code ?
You can see my demo(https://github.com/tran-the-lam/debug-fiberi18n) Step 1: go run main.go Step 2:
. scripts/concurrent_request.sh
Error:panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x135e679] goroutine 10 [running]: github.com/valyala/fasthttp.(*RequestCtx).URI(...) /Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:952 github.com/valyala/fasthttp.(*RequestCtx).QueryArgs(0x0) /Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:991 +0x19 github.com/gofiber/fiber/v2.(*Ctx).Query(0xc00020c000, {0x150c47b, 0x4}, {0x0, 0x0, 0x0?}) /Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/ctx.go:1054 +0x45 test/fiberi18n.defaultLangHandler(0xc000860086?, {0x152a6d4, 0x2}) /Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/fiberi18n/config.go:80 +0x3f test/fiberi18n.GetMessage({0x1488ce0?, 0x15bf2b0?}) /Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/fiberi18n/i18n.go:105 +0x86 test/fiberi18n.MustGetMessage(...) /Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/fiberi18n/i18n.go:85 main.main.func1(0xc0000e0840) /Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/main.go:24 +0x6a github.com/gofiber/fiber/v2.(*App).next(0xc000080d80, 0xc0000e0840) /Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/router.go:144 +0x1bf github.com/gofiber/fiber/v2.(*Ctx).Next(0xc0001de000?) /Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/ctx.go:913 +0x53 test/fiberi18n.New.func1(0x14a5680?) /Users/user/Documents/workspace/ PiScale/Source Code/CHAT/debug_fiberi18n/fiberi18n/i18n.go:25 +0x5e github.com/gofiber/fiber/v2.(*App).next(0xc000080d80, 0xc0000e0840) /Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/router.go:144 +0x1bf github.com/gofiber/fiber/v2.(*App).handler(0xc000080d80, 0x10860f7?) /Users/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.45.0/router.go:171 +0x87 github.com/valyala/fasthttp.(*Server).serveConn(0xc0001bc000, {0x15c5640?, 0xc00028c170}) /Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:2365 +0x11d3 github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc0000ccf00, 0xc0000720c0) /Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/workerpool.go:224 +0xa9 github.com/valyala/fasthttp.(*workerPool).getCh.func1() /Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/workerpool.go:196 +0x38 created by github.com/valyala/fasthttp.(*workerPool).getCh /Users/user/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/workerpool.go:195 +0x1b0 exit status 2
In fact, although I didn't use methods like
utils.CopyString()
, I didn't get a panic when I executed this script 🤔
@Skyenought In your test you only request with the same local, you can make it random and send several different requests with several different locals at the same time
think you need to copy the value and use a safe map for concurrency
problem should be the place already mentioned by me
@ReneWerner87 I'll try to fix it again.
Hi, I think I have found the bug and it's placed here.
https://github.com/gofiber/contrib/blob/2bad1b1d10b4f1bbc0196947feb679d0b8f81c9d/fiberi18n/i18n.go#L24
When using utils.CopyString
on c.Query
and c.Get
and assigning header and query there to appCfg
instead of assigning whole ctx
to appCfg
I could not face this error again. But I'm new to go and I might be wrong 😅
Hi team!
I have an issue. When there are many concurrent requests to our system, fiberi18n throws error like this
My code implemented:
Please help me to solve this problem.