GithubHelp home page GithubHelp logo

Comments (23)

Skyenought avatar Skyenought commented on August 11, 2024 1

I will be making a pull request to fix the known issues

from contrib.

Skyenought avatar Skyenought commented on August 11, 2024 1

yes, i will

from contrib.

ReneWerner87 avatar ReneWerner87 commented on August 11, 2024

@Skyenought can you help here

from contrib.

Skyenought avatar Skyenought commented on August 11, 2024

let me see.

from contrib.

tran-the-lam avatar tran-the-lam commented on August 11, 2024

@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.

Skyenought avatar Skyenought commented on August 11, 2024

@tran-the-lam show your code ?

from contrib.

ReneWerner87 avatar ReneWerner87 commented on August 11, 2024

had you read article -> https://docs.gofiber.io/#zero-allocation

from contrib.

tran-the-lam avatar tran-the-lam commented on August 11, 2024

@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.

ReneWerner87 avatar ReneWerner87 commented on August 11, 2024

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.

tran-the-lam avatar tran-the-lam commented on August 11, 2024

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.

tran-the-lam avatar tran-the-lam commented on August 11, 2024

Maybe gofiber/contrib/fiberi18n has the same problem

lang = c.Get("Accept-Language")

from contrib.

ReneWerner87 avatar ReneWerner87 commented on August 11, 2024

https://github.com/tran-the-lam/debug-fiberi18n/blob/c9740c79fa469dc833cb466f5db3528e5b578d2a/fiberi18n/i18n.go#L106

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.

ReneWerner87 avatar ReneWerner87 commented on August 11, 2024

@Skyenought same problem is here
https://github.com/gofiber/contrib/blob/2bad1b1d10b4f1bbc0196947feb679d0b8f81c9d/fiberi18n/i18n.go#LL106C45-L106C49

we need better unittests

from contrib.

Skyenought avatar Skyenought commented on August 11, 2024

@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.

Skyenought avatar Skyenought commented on August 11, 2024

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.

tran-the-lam avatar tran-the-lam commented on August 11, 2024

@Skyenought Is this line already in your source test?

from contrib.

Skyenought avatar Skyenought commented on August 11, 2024

@tran-the-lam ok, i will fix them

from contrib.

Skyenought avatar Skyenought commented on August 11, 2024

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.

tran-the-lam avatar tran-the-lam commented on August 11, 2024

Recover link not found

from contrib.

Skyenought avatar Skyenought commented on August 11, 2024

https://docs.gofiber.io/api/middleware/recover

from contrib.

ReneWerner87 avatar ReneWerner87 commented on August 11, 2024

@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.

Skyenought avatar Skyenought commented on August 11, 2024

@ReneWerner87 I'll try to fix it again.

from contrib.

KompocikDot avatar KompocikDot commented on August 11, 2024

Hi, I think I have found the bug and it's placed here.

appCfg.ctx = c

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.