contrib: fiberi18n error on concurrent requests

Hi team!

I have an issue. When there are many concurrent requests to our system, fiberi18n throws error like this

[2023-05-16T04:55:32.634958995Z] 57398fb9-da68-4ea2-b008-51da27c5a0ab:: 200  -  GET      /threads 7.703849ms -​
fatal error: concurrent map writes
fatal error: concurrent map writes

goroutine 172 [running]:
github.com/gofiber/contrib/fiberi18n.New.func1(0xc0002282c0)
	/go/pkg/mod/github.com/gofiber/contrib/fiberi18n@v0.1.0/i18n.go:42 +0x209
github.com/gofiber/fiber/v2.(*App).next(0xc0001b8480, 0xc0002282c0)
	/go/pkg/mod/github.com/gofiber/fiber/v2@v2.42.0/router.go:134 +0x1b6
github.com/gofiber/fiber/v2.(*App).handler(0xc0001b8480, 0x4cc317?)
	/go/pkg/mod/github.com/gofiber/fiber/v2@v2.42.0/router.go:160 +0x87
github.com/valyala/fasthttp.(*Server).serveConn(0xc00054c200, {0xf7e6f8?, 0xc0000aa1b0})
	/go/pkg/mod/github.com/valyala/fasthttp@v1.45.0/server.go:2371 +0x11d3
github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc000539720, 0xc0000c0b60)
	/go/pkg/mod/github.com/valyala/fasthttp@v1.45.0/workerpool.go:224 +0xa9
github.com/valyala/fasthttp.(*workerPool).getCh.func1()
	/go/pkg/mod/github.com/valyala/fasthttp@v1.45.0/workerpool.go:196 +0x38
created by github.com/valyala/fasthttp.(*workerPool).getCh
	/go/pkg/mod/github.com/valyala/fasthttp@v1.45.0/workerpool.go:195 +0x1b0

goroutine 1 [IO wait, 1 minutes]:
internal/poll.runtime_pollWait(0x7fb9247119b8, 0x72)
	/usr/local/go/src/runtime/netpoll.go:306 +0x89
internal/poll.(*pollDesc).wait(0xc0004ad100?, 0x4?, 0x0)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:84 +0x32
internal/poll.(*pollDesc).waitRead(...)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:89
internal/poll.(*FD).Accept(0xc0004ad100)
	/usr/local/go/src/internal/poll/fd_unix.go:614 +0x2bd
net.(*netFD).accept(0xc0004ad100)
	/usr/local/go/src/net/fd_unix.go:172 +0x35
net.(*TCPListener).accept(0xc0004c5950)
	/usr/local/go/src/net/tcpsock_posix.go:148 +0x25
net.(*TCPListener).Accept(0xc0004c5950)
	/usr/local/go/src/net/tcpsock.go:297 +0x3d
github.com/valyala/fasthttp.acceptConn(0xc00054c200, {0xf7a710, 0xc0004c5950}, 0xc0006938b8)
	/go/pkg/mod/github.com/valyala/fasthttp@v1.45.0/server.go:1930 +0x62
github.com/valyala/fasthttp.(*Server).Serve(0xc00054c200, {0xf7a710?, 0xc0004c5950})
	/go/pkg/mod/github.com/valyala/fasthttp@v1.45.0/server.go:1823 +0x4f4
github.com/gofiber/fiber/v2.(*App).Listen(0xc0001b8480, {0xe3e28a?, 0xd52f40?})
	/go/pkg/mod/github.com/gofiber/fiber/v2@v2.42.0/listen.go:82 +0x110
main.main()
	/build/cmd/api/api.go:119 +0x357

My code implemented:

app.Use(
		fiberi18n.New(&fiberi18n.Config{
			RootPath:        "./localize",
			AcceptLanguages: []language.Tag{language.Vietnamese, language.English},
			DefaultLanguage: language.English,
		}),
	)
 msg := fiberi18n.MustGetMessage("successfully")

Please help me to solve this problem.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 23 (16 by maintainers)

Most upvoted comments

yes, i will

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