Describe the bug
Services running in docker containers are often stopped abnormally and an error is reported after viewing the log. fatal error: concurrent map read and map write
To Reproduce
Personal guesswork is associated with concurrency
Expected behavior
Services will no longer be abnormally shut down due to this problem
Screenshots and logs
fatal error: concurrent map read and map write
time="2022-01-11 15:04:32" level=warning msg="exhaust/upload/2022/01/image-ffc82761be954da7bb36b14548044614-thumbnail.png.1641562072.avif not found on filesystem" func="[230:main.findSmallestFiles()]"
time="2022-01-11 15:04:32" level=warning msg="exhaust/upload/2022/01/image-e9c118d4b35f4b6f86dbd03b6d5e2cc7-thumbnail.png.1641562035.avif not found on filesystem" func="[230:main.findSmallestFiles()]"
goroutine 12 [running]:
runtime.throw({0x8560a8, 0x0})
/usr/local/go/src/runtime/panic.go:1198 +0x71 fp=0xc000181338 sp=0xc000181308 pc=0x43d691
runtime.mapaccess1(0xc0000d7900, 0xc000021d10, 0x1b00)
/usr/local/go/src/runtime/map.go:411 +0x1f7 fp=0xc000181378 sp=0xc000181338 pc=0x418797
github.com/h2non/filetype.Match({0xc0000d7900, 0x4, 0x1227})
/go/pkg/mod/github.com/h2non/[email protected]/match.go:28 +0x22c fp=0xc000181500 sp=0xc000181378 pc=0x70ccec
main.getFileContentType({0xc0000d7900, 0x1226, 0x1227})
/build/helper.go:38 +0x14e fp=0xc000181658 sp=0xc000181500 pc=0x74c4ae
main.convert(0xc000262000)
/build/router.go:91 +0x82f fp=0xc000181818 sp=0xc000181658 pc=0x74ee6f
github.com/gofiber/fiber/v2.(*App).next(0xc000124c60, 0xc000262000)
/go/pkg/mod/github.com/webp-sh/fiber/[email protected]/router.go:126 +0x1d8 fp=0xc0001818b8 sp=0xc000181818 pc=0x740b98
github.com/gofiber/fiber/v2.(*Ctx).Next(0x6da2e5)
/go/pkg/mod/github.com/webp-sh/fiber/[email protected]/ctx.go:637 +0x53 fp=0xc0001818d8 sp=0xc0001818b8 pc=0x73c953
github.com/gofiber/fiber/v2/middleware/logger.New.func2(0xc000262000)
/go/pkg/mod/github.com/webp-sh/fiber/[email protected]/middleware/logger/logger.go:154 +0x22b fp=0xc000181b70 sp=0xc0001818d8 pc=0x7478eb
github.com/gofiber/fiber/v2.(*App).next(0xc000124c60, 0xc000262000)
/go/pkg/mod/github.com/webp-sh/fiber/[email protected]/router.go:126 +0x1d8 fp=0xc000181c10 sp=0xc000181b70 pc=0x740b98
github.com/gofiber/fiber/v2.(*App).handler(0xc000124c60, 0x4b2377)
/go/pkg/mod/github.com/webp-sh/fiber/[email protected]/router.go:154 +0xe5 fp=0xc000181c48 sp=0xc000181c10 pc=0x740da5
github.com/gofiber/fiber/v2.(*App).handler-fm(0xc000126f00)
/go/pkg/mod/github.com/webp-sh/fiber/[email protected]/router.go:142 +0x2c fp=0xc000181c68 sp=0xc000181c48 pc=0x74462c
github.com/valyala/fasthttp.(*Server).serveConn(0xc000128b40, {0x8d5cd0, 0xc0000106e8})
/go/pkg/mod/github.com/valyala/[email protected]/server.go:2168 +0xf2b fp=0xc000181ec8 sp=0xc000181c68 pc=0x6f912b
github.com/valyala/fasthttp.(*Server).serveConn-fm({0x8d5cd0, 0xc0000106e8})
/go/pkg/mod/github.com/valyala/[email protected]/server.go:1959 +0x39 fp=0xc000181ef0 sp=0xc000181ec8 pc=0x7023b9
github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc00011d360, 0xc000057840)
/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:223 +0xa9 fp=0xc000181fa0 sp=0xc000181ef0 pc=0x700669
github.com/valyala/fasthttp.(*workerPool).getCh.func1()
/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:195 +0x38 fp=0xc000181fe0 sp=0xc000181fa0 pc=0x7003f8
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000181fe8 sp=0xc000181fe0 pc=0x46cbe1
created by github.com/valyala/fasthttp.(*workerPool).getCh
/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:194 +0x1b5
goroutine 1 [IO wait]:
internal/poll.runtime_pollWait(0x7f7104f6aa48, 0x72)
/usr/local/go/src/runtime/netpoll.go:234 +0x89
internal/poll.(*pollDesc).wait(0xc00014eb00, 0xc00002a000, 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(0xc00014eb00)
/usr/local/go/src/internal/poll/fd_unix.go:402 +0x22c
net.(*netFD).accept(0xc00014eb00)
/usr/local/go/src/net/fd_unix.go:173 +0x35
net.(*TCPListener).accept(0xc00000e6f0)
/usr/local/go/src/net/tcpsock_posix.go:140 +0x28
net.(*TCPListener).Accept(0xc00000e6f0)
/usr/local/go/src/net/tcpsock.go:262 +0x3d
github.com/valyala/fasthttp.acceptConn(0xc000128b40, {0x8cfe28, 0xc00000e6f0}, 0xc0000c7c70)
/go/pkg/mod/github.com/valyala/[email protected]/server.go:1788 +0x62
github.com/valyala/fasthttp.(*Server).Serve(0xc000128b40, {0x8cfe28, 0xc00000e6f0})
/go/pkg/mod/github.com/valyala/[email protected]/server.go:1703 +0x4e5
github.com/gofiber/fiber/v2.(*App).Listen(0xc000124c60, {0xc000026ea4, 0xc00018fdc8})
/go/pkg/mod/github.com/webp-sh/fiber/[email protected]/app.go:574 +0xb5
main.main()
/build/webp-server.go:117 +0x607
goroutine 28 [sleep]:
time.Sleep(0x12a05f200)
/usr/local/go/src/runtime/time.go:193 +0x12e
github.com/valyala/fasthttp.(*FS).initRequestHandler.func1()
/go/pkg/mod/github.com/valyala/[email protected]/fs.go:403 +0x50
created by github.com/valyala/fasthttp.(*FS).initRequestHandler
/go/pkg/mod/github.com/valyala/[email protected]/fs.go:400 +0x3e5
goroutine 7 [sleep]:
time.Sleep(0x1dcd6500)
/usr/local/go/src/runtime/time.go:193 +0x12e
github.com/gofiber/fiber/v2/middleware/logger.New.func1()
/go/pkg/mod/github.com/webp-sh/fiber/[email protected]/middleware/logger/logger.go:99 +0x75
created by github.com/gofiber/fiber/v2/middleware/logger.New
/go/pkg/mod/github.com/webp-sh/fiber/[email protected]/middleware/logger/logger.go:97 +0x325
goroutine 29 [sleep]:
time.Sleep(0x3b9aca00)
/usr/local/go/src/runtime/time.go:193 +0x12e
github.com/valyala/fasthttp.updateServerDate.func1()
/go/pkg/mod/github.com/valyala/[email protected]/header.go:1438 +0x1e
created by github.com/valyala/fasthttp.updateServerDate
/go/pkg/mod/github.com/valyala/[email protected]/header.go:1436 +0x27
goroutine 8 [sleep]:
time.Sleep(0x2540be400)
/usr/local/go/src/runtime/time.go:193 +0x12e
github.com/valyala/fasthttp.(*workerPool).Start.func2()
/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:66 +0x56
created by github.com/valyala/fasthttp.(*workerPool).Start
/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:58 +0xde
goroutine 30 [runnable]:
github.com/h2non/filetype.Match({0xc00024c800, 0x1598, 0x1599})
/go/pkg/mod/github.com/h2non/[email protected]/match.go:21 +0x4ab
main.getFileContentType({0xc00024c800, 0x1598, 0x1599})
/build/helper.go:38 +0x14e
main.convert(0xc00012edc0)
/build/router.go:91 +0x82f
github.com/gofiber/fiber/v2.(*App).next(0xc000124c60, 0xc00012edc0)
/go/pkg/mod/github.com/webp-sh/fiber/[email protected]/router.go:126 +0x1d8
github.com/gofiber/fiber/v2.(*Ctx).Next(0x6da2e5)
/go/pkg/mod/github.com/webp-sh/fiber/[email protected]/ctx.go:637 +0x53
github.com/gofiber/fiber/v2/middleware/logger.New.func2(0xc00012edc0)
/go/pkg/mod/github.com/webp-sh/fiber/[email protected]/middleware/logger/logger.go:154 +0x22b
github.com/gofiber/fiber/v2.(*App).next(0xc000124c60, 0xc00012edc0)
/go/pkg/mod/github.com/webp-sh/fiber/[email protected]/router.go:126 +0x1d8
github.com/gofiber/fiber/v2.(*App).handler(0xc000124c60, 0x4b2377)
/go/pkg/mod/github.com/webp-sh/fiber/[email protected]/router.go:154 +0xe5
github.com/valyala/fasthttp.(*Server).serveConn(0xc000128b40, {0x8d5cd0, 0xc0000106e0})
/go/pkg/mod/github.com/valyala/[email protected]/server.go:2168 +0xf2b
github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc00011d360, 0xc0004520c0)
/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:223 +0xa9
github.com/valyala/fasthttp.(*workerPool).getCh.func1()
/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:195 +0x38
created by github.com/valyala/fasthttp.(*workerPool).getCh
/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:194 +0x1b5
goroutine 25 [IO wait]:
internal/poll.runtime_pollWait(0x7f7104f6a960, 0x72)
/usr/local/go/src/runtime/netpoll.go:234 +0x89
internal/poll.(*pollDesc).wait(0xc00014ec00, 0xc000284000, 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).Read(0xc00014ec00, {0xc000284000, 0xe03, 0xe03})
/usr/local/go/src/internal/poll/fd_unix.go:167 +0x25a
net.(*netFD).Read(0xc00014ec00, {0xc000284000, 0x893, 0xc00049b2c0})
/usr/local/go/src/net/fd_posix.go:56 +0x29
net.(*conn).Read(0xc00008a048, {0xc000284000, 0x5d5279, 0xc0002577f8})
/usr/local/go/src/net/net.go:183 +0x45
crypto/tls.(*atLeastReader).Read(0xc00047c888, {0xc000284000, 0x0, 0x413fed})
/usr/local/go/src/crypto/tls/conn.go:777 +0x3d
bytes.(*Buffer).ReadFrom(0xc0000f0278, {0x8c9820, 0xc00047c888})
/usr/local/go/src/bytes/buffer.go:204 +0x98
crypto/tls.(*Conn).readFromUntil(0xc0000f0000, {0x8c9fa0, 0xc00008a048}, 0xc000284575)
/usr/local/go/src/crypto/tls/conn.go:799 +0xe5
crypto/tls.(*Conn).readRecordOrCCS(0xc0000f0000, 0x0)
/usr/local/go/src/crypto/tls/conn.go:606 +0x112
crypto/tls.(*Conn).readRecord(...)
/usr/local/go/src/crypto/tls/conn.go:574
crypto/tls.(*Conn).Read(0xc0000f0000, {0xc000285000, 0x1000, 0xc0000ac000})
/usr/local/go/src/crypto/tls/conn.go:1277 +0x16f
bufio.(*Reader).Read(0xc0004b5800, {0xc0004c8e38, 0x9, 0xc000080660})
/usr/local/go/src/bufio/bufio.go:227 +0x1b4
io.ReadAtLeast({0x8c9700, 0xc0004b5800}, {0xc0004c8e38, 0x9, 0x9}, 0x9)
/usr/local/go/src/io/io.go:328 +0x9a
io.ReadFull(...)
/usr/local/go/src/io/io.go:347
net/http.http2readFrameHeader({0xc0004c8e38, 0x9, 0xc0004d17d0}, {0x8c9700, 0xc0004b5800})
/usr/local/go/src/net/http/h2_bundle.go:1555 +0x6e
net/http.(*http2Framer).ReadFrame(0xc0004c8e00)
/usr/local/go/src/net/http/h2_bundle.go:1813 +0x95
net/http.(*http2clientConnReadLoop).run(0xc000257f98)
/usr/local/go/src/net/http/h2_bundle.go:8600 +0x130
net/http.(*http2ClientConn).readLoop(0xc00019a000)
/usr/local/go/src/net/http/h2_bundle.go:8523 +0x6f
created by net/http.(*http2Transport).newClientConn
/usr/local/go/src/net/http/h2_bundle.go:7317 +0xb85
Environment (please complete the following information):
- OS: CentOS 7.9
- Docker: 20.10.12-3
- webp_server_go: 0.4.1