Comments (23)
I will be making a pull request to fix the known issues
from contrib.
yes, i will
from contrib.
@Skyenought can you help here
from contrib.
let me see.
from contrib.
@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/[email protected]/server.go:952
github.com/valyala/fasthttp.(*RequestCtx).QueryArgs(0x0)
/Users/user/go/pkg/mod/github.com/valyala/[email protected]/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/[email protected]/ctx.go:1054 +0x45
my-fiberi18n/pkg/i18n.defaultLangHandler(0xc000860086?, {0x1a80bae, 0x2})
from contrib.
@tran-the-lam show your code ?
from contrib.
had you read article -> https://docs.gofiber.io/#zero-allocation
from contrib.
@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/[email protected]/server.go:952
github.com/valyala/fasthttp.(*RequestCtx).QueryArgs(0x0)
/Users/user/go/pkg/mod/github.com/valyala/[email protected]/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/[email protected]/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/[email protected]/router.go:144 +0x1bf
github.com/gofiber/fiber/v2.(*Ctx).Next(0xc0001de000?)
/Users/user/go/pkg/mod/github.com/gofiber/fiber/[email protected]/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/[email protected]/router.go:144 +0x1bf
github.com/gofiber/fiber/v2.(*App).handler(0xc000080d80, 0x10860f7?)
/Users/user/go/pkg/mod/github.com/gofiber/fiber/[email protected]/router.go:171 +0x87
github.com/valyala/fasthttp.(*Server).serveConn(0xc0001bc000, {0x15c5640?, 0xc00028c170})
/Users/user/go/pkg/mod/github.com/valyala/[email protected]/server.go:2365 +0x11d3
github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc0000ccf00, 0xc0000720c0)
/Users/user/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:224 +0xa9
github.com/valyala/fasthttp.(*workerPool).getCh.func1()
/Users/user/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:196 +0x38
created by github.com/valyala/fasthttp.(*workerPool).getCh
/Users/user/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:195 +0x1b0
exit status 2
from contrib.
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
from contrib.
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
}
from contrib.
Maybe gofiber/contrib/fiberi18n has the same problem
Line 85 in 2bad1b1
from contrib.
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
from contrib.
@Skyenought same problem is here
https://github.com/gofiber/contrib/blob/2bad1b1d10b4f1bbc0196947feb679d0b8f81c9d/fiberi18n/i18n.go#LL106C45-L106C49
we need better unittests
from contrib.
@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/[email protected]/server.go:952 github.com/valyala/fasthttp.(*RequestCtx).QueryArgs(0x0) /Users/user/go/pkg/mod/github.com/valyala/[email protected]/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/[email protected]/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/[email protected]/router.go:144 +0x1bf github.com/gofiber/fiber/v2.(*Ctx).Next(0xc0001de000?) /Users/user/go/pkg/mod/github.com/gofiber/fiber/[email protected]/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/[email protected]/router.go:144 +0x1bf github.com/gofiber/fiber/v2.(*App).handler(0xc000080d80, 0x10860f7?) /Users/user/go/pkg/mod/github.com/gofiber/fiber/[email protected]/router.go:171 +0x87 github.com/valyala/fasthttp.(*Server).serveConn(0xc0001bc000, {0x15c5640?, 0xc00028c170}) /Users/user/go/pkg/mod/github.com/valyala/[email protected]/server.go:2365 +0x11d3 github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc0000ccf00, 0xc0000720c0) /Users/user/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:224 +0xa9 github.com/valyala/fasthttp.(*workerPool).getCh.func1() /Users/user/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:196 +0x38 created by github.com/valyala/fasthttp.(*workerPool).getCh /Users/user/go/pkg/mod/github.com/valyala/[email protected]/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 🤔
from contrib.
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)
from contrib.
@Skyenought Is this line already in your source test?
from contrib.
@tran-the-lam ok, i will fix them
from contrib.
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 😖
from contrib.
Recover link not found
from contrib.
https://docs.gofiber.io/api/middleware/recover
from contrib.
@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/[email protected]/server.go:952 github.com/valyala/fasthttp.(*RequestCtx).QueryArgs(0x0) /Users/user/go/pkg/mod/github.com/valyala/[email protected]/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/[email protected]/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/[email protected]/router.go:144 +0x1bf github.com/gofiber/fiber/v2.(*Ctx).Next(0xc0001de000?) /Users/user/go/pkg/mod/github.com/gofiber/fiber/[email protected]/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/[email protected]/router.go:144 +0x1bf github.com/gofiber/fiber/v2.(*App).handler(0xc000080d80, 0x10860f7?) /Users/user/go/pkg/mod/github.com/gofiber/fiber/[email protected]/router.go:171 +0x87 github.com/valyala/fasthttp.(*Server).serveConn(0xc0001bc000, {0x15c5640?, 0xc00028c170}) /Users/user/go/pkg/mod/github.com/valyala/[email protected]/server.go:2365 +0x11d3 github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc0000ccf00, 0xc0000720c0) /Users/user/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:224 +0xa9 github.com/valyala/fasthttp.(*workerPool).getCh.func1() /Users/user/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:196 +0x38 created by github.com/valyala/fasthttp.(*workerPool).getCh /Users/user/go/pkg/mod/github.com/valyala/[email protected]/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
from contrib.
@ReneWerner87 I'll try to fix it again.
from contrib.
Hi, I think I have found the bug and it's placed here.
Line 24 in 2bad1b1
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 😅from contrib.
Related Issues (20)
- 🚀 [Feature]: My (simple) SSEFiber Package HOT 1
- 🤗 [Question]: Could you mint a new release? HOT 3
- 🤗 [Question]: Not sure how the socket.io requests are being handled HOT 5
- 🐛 [Bug]: Websocket write tcp4 127.0.0.1:8001->127.0.0.1:59510: write: broken pipe HOT 3
- 🤗 [Question]: websocket.Conn.Locals vs fiber.Ctx.Locals signature difference
- 🤗 [Question]: How does socketio differentiate between TextMessage and BinaryMessage? HOT 4
- 🚀 [Feature]: JWT unsupport fiber v3 HOT 5
- 🚀 [Feature]: contrib/swagger.go exposes internal adresses. There should be a possibility to self-host
- 🐛 [Bug]: Otelfiber blocks stream writers HOT 1
- 🐛 [Bug]: Segfault with WS compression HOT 2
- 🤗 [Question]: Is there any updates about fiber v3 support for middlewares such a otelfiber?
- 🚀 [Feature]: i18n refactoring from middleware to global container HOT 2
- 🚀 [Feature]: Support Cerbos HOT 5
- 🚀 [Feature]: Custom metric attributes for otelfiber
- 🤗 [Question]: is it possible to get the file descriptor from fiber websocket? HOT 1
- 🐛 [Bug]: error occored when import github.com/gofiber/contrib/websocket HOT 7
- 🚀 [Feature]: Otelfiber allow for manual cancellation of c.UserContext() in otelfiber.Middleware() HOT 1
- 🐛 [Bug]: FiberSentry: GetHubFromContext() never returns nil
- 🚀 [Feature]: Add golangci-lint
- 🤗 [Question]: fiberzerolog the banner is not printed. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from contrib.