Commit Graph

95 Commits

Author SHA1 Message Date
M. Efe Çetin ee34656bec fs: fix openIndexFile when dirPath is empty string (#1779) 2024-05-19 15:11:58 +02:00
M. Efe Çetin aadadb913a fs: fix GenerateIndexPages when DirFS or embed.FS is used (#1778) 2024-05-18 10:30:01 +02:00
Limux 091733b08e Implemented what was described by me in #1766. (#1767)
* Implemented what was described by me in issue#1766.

* fixed linting isssues in fs.go with gofmt -e -d -s

---------

Co-authored-by: Raphael Habichler <raphael.habichler@bmd.at>
2024-04-29 21:37:39 +02:00
Oleksandr Redko bbc7bd04e2 refactor: rename error local variables (#1738) 2024-03-25 14:30:27 +01:00
Oleksandr Redko 3166afd835 Enable few gocritic checks; fix up issues (#1728) 2024-03-02 16:19:05 +01:00
Co1a 5f81476d7c feat:support zstd compress and uncompressed (#1701)
* feat:support zstd compress and uncompressed

* fix:real & stackless write using different pool to avoid get stackless.writer

* fix:zstd normalize compress level

* Change empty string checks to be more idiomatic (#1684)

* chore:lint fix and rebase with master

* chore:remove 1.18 test & upgrade compress version

* fix:error default compress level

* Fix lint

---------

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2024-02-21 07:21:52 +01:00
Oleksandr Redko 190204cf1a Upgrade golangci-lint to v1.56.2; fix gocritic issues (#1722) 2024-02-21 05:51:28 +01:00
Oleksandr Redko 28615eba55 Change empty string checks to be more idiomatic (#1684) 2024-01-04 15:05:38 +01:00
Oleksandr Redko 9d6b470260 chore: Add missing dots at the end of comments (#1677) 2023-12-13 13:56:24 +08:00
Oleksandr Redko 12949de784 chore: Set max line length to 130 characters (#1676) 2023-12-05 19:49:41 +01:00
Oleksandr Redko 8ecfc989d9 Enable dupword, unconvert linters (#1658) 2023-11-12 16:42:39 +01:00
Tiago Peczenyj dfce853067 Skip fs cache based on config (#1644)
* add cache manager struce

* refactor cache by adding interface

* generalize ctor

* implement feature add unit tests

* fix code

* rename fs field as filesystem
2023-11-05 19:31:04 +01:00
Tiago Peczenyj 4010b16eef Add support to fs.fs on serve static files (#1640)
* substitute *os.File by fs.File

* refactor error handling by using the new recommended form

* finish implementation

* substitute seek(offset,0) by seek(offset, io.SeekStart)

* add unit test

* use io.SeekStart on Seek method
2023-11-05 14:46:42 +01:00
leonklingele f0865d4aab fs: fix race condition on global map (#1565)
* fs: fix race condition on global map

Previously, when creating multiple FS instances with a non-empty
"CompressedFileSuffix" field concurrently, a data race on the global
"FSCompressedFileSuffixes" might occur.

This was found in fiber, probably the largest web framework based on fasthttp:

    git clone https://github.com/gofiber/fiber.git && cd fiber
    git checkout 182f9f09705eab40c61a618835d46faee79c1e49
    go test -v -race -run Test_App_Static_Prefix_*

        === RUN   Test_App_Static_Prefix_Wildcard
    === PAUSE Test_App_Static_Prefix_Wildcard
    === RUN   Test_App_Static_Prefix
    === PAUSE Test_App_Static_Prefix
    === CONT  Test_App_Static_Prefix
    === CONT  Test_App_Static_Prefix_Wildcard
    ==================
    WARNING: DATA RACE
    Write at 0x00c0001b1c50 by goroutine 7:
      runtime.mapassign_faststr()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/runtime/map_faststr.go:203 +0x0
      github.com/valyala/fasthttp.(*FS).initRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:434 +0x2c4
      github.com/valyala/fasthttp.(*FS).initRequestHandler-fm()
          <autogenerated>:1 +0x39
      sync.(*Once).doSlow()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:74 +0x101
      sync.(*Once).Do()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:65 +0x46
      github.com/valyala/fasthttp.(*FS).NewRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:389 +0x9bb
      github.com/gofiber/fiber/v2.(*App).registerStatic()
          /home/leon/code/fiber/router.go:396 +0x984
      github.com/gofiber/fiber/v2.(*App).Static()
          /home/leon/code/fiber/app.go:762 +0x84
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix_Wildcard()
          /home/leon/code/fiber/app_test.go:1017 +0x5c
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Previous write at 0x00c0001b1c50 by goroutine 8:
      runtime.mapassign_faststr()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/runtime/map_faststr.go:203 +0x0
      github.com/valyala/fasthttp.(*FS).initRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:434 +0x2c4
      github.com/valyala/fasthttp.(*FS).initRequestHandler-fm()
          <autogenerated>:1 +0x39
      sync.(*Once).doSlow()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:74 +0x101
      sync.(*Once).Do()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:65 +0x46
      github.com/valyala/fasthttp.(*FS).NewRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:389 +0x9bb
      github.com/gofiber/fiber/v2.(*App).registerStatic()
          /home/leon/code/fiber/router.go:396 +0x984
      github.com/gofiber/fiber/v2.(*App).Static()
          /home/leon/code/fiber/app.go:762 +0x84
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix()
          /home/leon/code/fiber/app_test.go:1042 +0x59
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Goroutine 7 (running) created at:
      testing.(*T).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x805
      testing.runTests.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2036 +0x8d
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.runTests()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2034 +0x87c
      testing.(*M).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1906 +0xb44
      main.main()
          _testmain.go:871 +0x2e9

    Goroutine 8 (running) created at:
      testing.(*T).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x805
      testing.runTests.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2036 +0x8d
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.runTests()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2034 +0x87c
      testing.(*M).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1906 +0xb44
      main.main()
          _testmain.go:871 +0x2e9
    ==================
    ==================
    WARNING: DATA RACE
    Write at 0x00c0001f43e8 by goroutine 7:
      github.com/valyala/fasthttp.(*FS).initRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:434 +0x2d3
      github.com/valyala/fasthttp.(*FS).initRequestHandler-fm()
          <autogenerated>:1 +0x39
      sync.(*Once).doSlow()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:74 +0x101
      sync.(*Once).Do()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:65 +0x46
      github.com/valyala/fasthttp.(*FS).NewRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:389 +0x9bb
      github.com/gofiber/fiber/v2.(*App).registerStatic()
          /home/leon/code/fiber/router.go:396 +0x984
      github.com/gofiber/fiber/v2.(*App).Static()
          /home/leon/code/fiber/app.go:762 +0x84
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix_Wildcard()
          /home/leon/code/fiber/app_test.go:1017 +0x5c
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Previous write at 0x00c0001f43e8 by goroutine 8:
      github.com/valyala/fasthttp.(*FS).initRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:434 +0x2d3
      github.com/valyala/fasthttp.(*FS).initRequestHandler-fm()
          <autogenerated>:1 +0x39
      sync.(*Once).doSlow()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:74 +0x101
      sync.(*Once).Do()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:65 +0x46
      github.com/valyala/fasthttp.(*FS).NewRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:389 +0x9bb
      github.com/gofiber/fiber/v2.(*App).registerStatic()
          /home/leon/code/fiber/router.go:396 +0x984
      github.com/gofiber/fiber/v2.(*App).Static()
          /home/leon/code/fiber/app.go:762 +0x84
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix()
          /home/leon/code/fiber/app_test.go:1042 +0x59
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Goroutine 7 (running) created at:
      testing.(*T).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x805
      testing.runTests.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2036 +0x8d
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.runTests()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2034 +0x87c
      testing.(*M).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1906 +0xb44
      main.main()
          _testmain.go:871 +0x2e9

    Goroutine 8 (running) created at:
      testing.(*T).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x805
      testing.runTests.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2036 +0x8d
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.runTests()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2034 +0x87c
      testing.(*M).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1906 +0xb44
      main.main()
          _testmain.go:871 +0x2e9
    ==================
    ==================
    WARNING: DATA RACE
    Read at 0x00c0001f43f8 by goroutine 7:
      github.com/valyala/fasthttp.(*FS).initRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:435 +0x344
      github.com/valyala/fasthttp.(*FS).initRequestHandler-fm()
          <autogenerated>:1 +0x39
      sync.(*Once).doSlow()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:74 +0x101
      sync.(*Once).Do()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:65 +0x46
      github.com/valyala/fasthttp.(*FS).NewRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:389 +0x9bb
      github.com/gofiber/fiber/v2.(*App).registerStatic()
          /home/leon/code/fiber/router.go:396 +0x984
      github.com/gofiber/fiber/v2.(*App).Static()
          /home/leon/code/fiber/app.go:762 +0x84
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix_Wildcard()
          /home/leon/code/fiber/app_test.go:1017 +0x5c
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Previous write at 0x00c0001f43f8 by goroutine 8:
      github.com/valyala/fasthttp.(*FS).initRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:435 +0x38c
      github.com/valyala/fasthttp.(*FS).initRequestHandler-fm()
          <autogenerated>:1 +0x39
      sync.(*Once).doSlow()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:74 +0x101
      sync.(*Once).Do()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:65 +0x46
      github.com/valyala/fasthttp.(*FS).NewRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:389 +0x9bb
      github.com/gofiber/fiber/v2.(*App).registerStatic()
          /home/leon/code/fiber/router.go:396 +0x984
      github.com/gofiber/fiber/v2.(*App).Static()
          /home/leon/code/fiber/app.go:762 +0x84
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix()
          /home/leon/code/fiber/app_test.go:1042 +0x59
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Goroutine 7 (running) created at:
      testing.(*T).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x805
      testing.runTests.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2036 +0x8d
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.runTests()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2034 +0x87c
      testing.(*M).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1906 +0xb44
      main.main()
          _testmain.go:871 +0x2e9

    Goroutine 8 (running) created at:
      testing.(*T).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x805
      testing.runTests.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2036 +0x8d
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.runTests()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2034 +0x87c
      testing.(*M).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1906 +0xb44
      main.main()
          _testmain.go:871 +0x2e9
    ==================
    ==================
    WARNING: DATA RACE
    Read at 0x00c0001b1c50 by goroutine 11:
      runtime.mapaccess1_faststr()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/runtime/map_faststr.go:13 +0x0
      github.com/valyala/fasthttp.(*fsHandler).newFSFile()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:1329 +0xec
      github.com/valyala/fasthttp.(*fsHandler).openFSFile()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:1317 +0x7c9
      github.com/valyala/fasthttp.(*fsHandler).handleRequest()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:865 +0x846
      github.com/valyala/fasthttp.(*fsHandler).handleRequest-fm()
          <autogenerated>:1 +0x44
      github.com/gofiber/fiber/v2.(*App).registerStatic.func3()
          /home/leon/code/fiber/router.go:403 +0x15e
      github.com/gofiber/fiber/v2.(*App).next()
          /home/leon/code/fiber/router.go:144 +0x50b
      github.com/gofiber/fiber/v2.(*App).handler()
          /home/leon/code/fiber/router.go:171 +0xf2
      github.com/gofiber/fiber/v2.(*App).handler-fm()
          <autogenerated>:1 +0x44
      github.com/valyala/fasthttp.(*Server).serveConn()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:2365 +0x1b4a
      github.com/valyala/fasthttp.(*Server).ServeConn()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:2035 +0x10f
      github.com/gofiber/fiber/v2.(*App).Test.func1()
          /home/leon/code/fiber/app.go:934 +0xd8

    Previous write at 0x00c0001b1c50 by goroutine 7:
      runtime.mapassign_faststr()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/runtime/map_faststr.go:203 +0x0
      github.com/valyala/fasthttp.(*FS).initRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:435 +0x37d
      github.com/valyala/fasthttp.(*FS).initRequestHandler-fm()
          <autogenerated>:1 +0x39
      sync.(*Once).doSlow()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:74 +0x101
      sync.(*Once).Do()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:65 +0x46
      github.com/valyala/fasthttp.(*FS).NewRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:389 +0x9bb
      github.com/gofiber/fiber/v2.(*App).registerStatic()
          /home/leon/code/fiber/router.go:396 +0x984
      github.com/gofiber/fiber/v2.(*App).Static()
          /home/leon/code/fiber/app.go:762 +0x84
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix_Wildcard()
          /home/leon/code/fiber/app_test.go:1017 +0x5c
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Goroutine 11 (running) created at:
      github.com/gofiber/fiber/v2.(*App).Test()
          /home/leon/code/fiber/app.go:926 +0x645
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix()
          /home/leon/code/fiber/app_test.go:1045 +0xba
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Goroutine 7 (running) created at:
      testing.(*T).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x805
      testing.runTests.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2036 +0x8d
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.runTests()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2034 +0x87c
      testing.(*M).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1906 +0xb44
      main.main()
          _testmain.go:871 +0x2e9
    ==================
    ==================
    WARNING: DATA RACE
    Write at 0x00c0001b1c50 by goroutine 8:
      runtime.mapassign_faststr()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/runtime/map_faststr.go:203 +0x0
      github.com/valyala/fasthttp.(*FS).initRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:434 +0x2c4
      github.com/valyala/fasthttp.(*FS).initRequestHandler-fm()
          <autogenerated>:1 +0x39
      sync.(*Once).doSlow()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:74 +0x101
      sync.(*Once).Do()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:65 +0x46
      github.com/valyala/fasthttp.(*FS).NewRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:389 +0x9bb
      github.com/gofiber/fiber/v2.(*App).registerStatic()
          /home/leon/code/fiber/router.go:396 +0x984
      github.com/gofiber/fiber/v2.(*App).Static()
          /home/leon/code/fiber/app.go:762 +0x2c6
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix()
          /home/leon/code/fiber/app_test.go:1051 +0x29b
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Previous write at 0x00c0001b1c50 by goroutine 7:
      runtime.mapassign_faststr()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/runtime/map_faststr.go:203 +0x0
      github.com/valyala/fasthttp.(*FS).initRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:434 +0x2c4
      github.com/valyala/fasthttp.(*FS).initRequestHandler-fm()
          <autogenerated>:1 +0x39
      sync.(*Once).doSlow()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:74 +0x101
      sync.(*Once).Do()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:65 +0x46
      github.com/valyala/fasthttp.(*FS).NewRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:389 +0x9bb
      github.com/gofiber/fiber/v2.(*App).registerStatic()
          /home/leon/code/fiber/router.go:396 +0x984
      github.com/gofiber/fiber/v2.(*App).Static()
          /home/leon/code/fiber/app.go:762 +0x2c9
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix_Wildcard()
          /home/leon/code/fiber/app_test.go:1026 +0x29b
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Goroutine 8 (running) created at:
      testing.(*T).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x805
      testing.runTests.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2036 +0x8d
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.runTests()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2034 +0x87c
      testing.(*M).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1906 +0xb44
      main.main()
          _testmain.go:871 +0x2e9

    Goroutine 7 (running) created at:
      testing.(*T).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x805
      testing.runTests.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2036 +0x8d
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.runTests()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2034 +0x87c
      testing.(*M).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1906 +0xb44
      main.main()
          _testmain.go:871 +0x2e9
    ==================
    ==================
    WARNING: DATA RACE
    Write at 0x00c0001f43e8 by goroutine 8:
      github.com/valyala/fasthttp.(*FS).initRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:434 +0x2d3
      github.com/valyala/fasthttp.(*FS).initRequestHandler-fm()
          <autogenerated>:1 +0x39
      sync.(*Once).doSlow()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:74 +0x101
      sync.(*Once).Do()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:65 +0x46
      github.com/valyala/fasthttp.(*FS).NewRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:389 +0x9bb
      github.com/gofiber/fiber/v2.(*App).registerStatic()
          /home/leon/code/fiber/router.go:396 +0x984
      github.com/gofiber/fiber/v2.(*App).Static()
          /home/leon/code/fiber/app.go:762 +0x2c6
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix()
          /home/leon/code/fiber/app_test.go:1051 +0x29b
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Previous write at 0x00c0001f43e8 by goroutine 7:
      github.com/valyala/fasthttp.(*FS).initRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:434 +0x2d3
      github.com/valyala/fasthttp.(*FS).initRequestHandler-fm()
          <autogenerated>:1 +0x39
      sync.(*Once).doSlow()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:74 +0x101
      sync.(*Once).Do()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:65 +0x46
      github.com/valyala/fasthttp.(*FS).NewRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:389 +0x9bb
      github.com/gofiber/fiber/v2.(*App).registerStatic()
          /home/leon/code/fiber/router.go:396 +0x984
      github.com/gofiber/fiber/v2.(*App).Static()
          /home/leon/code/fiber/app.go:762 +0x2c9
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix_Wildcard()
          /home/leon/code/fiber/app_test.go:1026 +0x29b
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Goroutine 8 (running) created at:
      testing.(*T).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x805
      testing.runTests.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2036 +0x8d
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.runTests()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2034 +0x87c
      testing.(*M).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1906 +0xb44
      main.main()
          _testmain.go:871 +0x2e9

    Goroutine 7 (running) created at:
      testing.(*T).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x805
      testing.runTests.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2036 +0x8d
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.runTests()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2034 +0x87c
      testing.(*M).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1906 +0xb44
      main.main()
          _testmain.go:871 +0x2e9
    ==================
    ==================
    WARNING: DATA RACE
    Read at 0x00c0001f43f8 by goroutine 8:
      github.com/valyala/fasthttp.(*FS).initRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:435 +0x344
      github.com/valyala/fasthttp.(*FS).initRequestHandler-fm()
          <autogenerated>:1 +0x39
      sync.(*Once).doSlow()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:74 +0x101
      sync.(*Once).Do()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:65 +0x46
      github.com/valyala/fasthttp.(*FS).NewRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:389 +0x9bb
      github.com/gofiber/fiber/v2.(*App).registerStatic()
          /home/leon/code/fiber/router.go:396 +0x984
      github.com/gofiber/fiber/v2.(*App).Static()
          /home/leon/code/fiber/app.go:762 +0x2c6
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix()
          /home/leon/code/fiber/app_test.go:1051 +0x29b
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Previous write at 0x00c0001f43f8 by goroutine 7:
      github.com/valyala/fasthttp.(*FS).initRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:435 +0x38c
      github.com/valyala/fasthttp.(*FS).initRequestHandler-fm()
          <autogenerated>:1 +0x39
      sync.(*Once).doSlow()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:74 +0x101
      sync.(*Once).Do()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:65 +0x46
      github.com/valyala/fasthttp.(*FS).NewRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:389 +0x9bb
      github.com/gofiber/fiber/v2.(*App).registerStatic()
          /home/leon/code/fiber/router.go:396 +0x984
      github.com/gofiber/fiber/v2.(*App).Static()
          /home/leon/code/fiber/app.go:762 +0x2c9
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix_Wildcard()
          /home/leon/code/fiber/app_test.go:1026 +0x29b
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Goroutine 8 (running) created at:
      testing.(*T).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x805
      testing.runTests.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2036 +0x8d
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.runTests()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2034 +0x87c
      testing.(*M).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1906 +0xb44
      main.main()
          _testmain.go:871 +0x2e9

    Goroutine 7 (running) created at:
      testing.(*T).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x805
      testing.runTests.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2036 +0x8d
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.runTests()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2034 +0x87c
      testing.(*M).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1906 +0xb44
      main.main()
          _testmain.go:871 +0x2e9
    ==================
    ==================
    WARNING: DATA RACE
    Write at 0x00c0001b1c50 by goroutine 8:
      runtime.mapassign_faststr()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/runtime/map_faststr.go:203 +0x0
      github.com/valyala/fasthttp.(*FS).initRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:434 +0x2c4
      github.com/valyala/fasthttp.(*FS).initRequestHandler-fm()
          <autogenerated>:1 +0x39
      sync.(*Once).doSlow()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:74 +0x101
      sync.(*Once).Do()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/sync/once.go:65 +0x46
      github.com/valyala/fasthttp.(*FS).NewRequestHandler()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:389 +0x9bb
      github.com/gofiber/fiber/v2.(*App).registerStatic()
          /home/leon/code/fiber/router.go:396 +0x984
      github.com/gofiber/fiber/v2.(*App).Static()
          /home/leon/code/fiber/app.go:762 +0x4f0
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix()
          /home/leon/code/fiber/app_test.go:1060 +0x4c5
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47

    Previous read at 0x00c0001b1c50 by goroutine 20:
      runtime.mapaccess1_faststr()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/runtime/map_faststr.go:13 +0x0
      github.com/valyala/fasthttp.(*fsHandler).newFSFile()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:1329 +0xec
      github.com/valyala/fasthttp.(*fsHandler).openFSFile()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:1317 +0x7c9
      github.com/valyala/fasthttp.(*fsHandler).handleRequest()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/fs.go:865 +0x846
      github.com/valyala/fasthttp.(*fsHandler).handleRequest-fm()
          <autogenerated>:1 +0x44
      github.com/gofiber/fiber/v2.(*App).registerStatic.func3()
          /home/leon/code/fiber/router.go:403 +0x15e
      github.com/gofiber/fiber/v2.(*App).next()
          /home/leon/code/fiber/router.go:144 +0x50b
      github.com/gofiber/fiber/v2.(*App).handler()
          /home/leon/code/fiber/router.go:171 +0xf2
      github.com/gofiber/fiber/v2.(*App).handler-fm()
          <autogenerated>:1 +0x44
      github.com/valyala/fasthttp.(*Server).serveConn()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:2365 +0x1b4a
      github.com/valyala/fasthttp.(*Server).ServeConn()
          /home/leon/go/pkg/mod/github.com/valyala/fasthttp@v1.47.0/server.go:2035 +0x10f
      github.com/gofiber/fiber/v2.(*App).Test.func1()
          /home/leon/code/fiber/app.go:934 +0xd8

    Goroutine 8 (running) created at:
      testing.(*T).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x805
      testing.runTests.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2036 +0x8d
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.runTests()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:2034 +0x87c
      testing.(*M).Run()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1906 +0xb44
      main.main()
          _testmain.go:871 +0x2e9

    Goroutine 20 (finished) created at:
      github.com/gofiber/fiber/v2.(*App).Test()
          /home/leon/code/fiber/app.go:926 +0x645
      github.com/gofiber/fiber/v2.Test_App_Static_Prefix_Wildcard()
          /home/leon/code/fiber/app_test.go:1028 +0x304
      testing.tRunner()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1576 +0x216
      testing.(*T).Run.func1()
          /nix/store/8v5zwymidmry0wd3lhj6zggskzsvqrfk-go-1.20.4/share/go/src/testing/testing.go:1629 +0x47
    ==================
        testing.go:1446: race detected during execution of test
    --- FAIL: Test_App_Static_Prefix_Wildcard (0.03s)
    === NAME  Test_App_Static_Prefix
        testing.go:1446: race detected during execution of test
    --- FAIL: Test_App_Static_Prefix (0.03s)
    FAIL
    exit status 1
    FAIL	github.com/gofiber/fiber/v2	0.050s

* Update fs.go

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>

---------

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2023-05-24 12:29:42 +02:00
Moritz Poldrack d0f2727a4d get rid of some panics (#1526)
* client: simplify (*HostClient).do()

Remove an allocation in favour of deferring a call to release the
response.

* client: remove panic in dialAddr

Return an error instead of panicking if the user supplied a nonsensical
DialFunc.

* compression: remove panic on invalid compression level

If a compression level exceeding gzip's boundaries is provided, fasthttp
will panic. Instead it would be better to handle this error for them by
limiting it to the minimum or maximum value, depending on the direction
the user has exceeded the limits.

Clamp the value of gzip to always be between gzip.BestSpeed and
gzip.BestCompression.

* peripconn: remove panic on negative connection count

When a negative count is reached when unregistering a connection, a
panic is caused even though data-integrity is not at risk.

Replace the panic() with a simple clamp on the value to ensure the
value does not exceed it's expected lower bounds.

References: #1504

* compress: remove error on failed nonblocking writes

Since there is no way of handling or even logging non-critical errors in
stateless non-blocking writecalls, just drop them and hope the user
notices and tries again.

* workerPool: remove panic on redundant Start and Stop calls

Instead of panicking for invalid behaviour, it's preferable to just turn
the function into a noop.

* http: remove panic on invalid form boundary

* http: remove panic on negative reads

Since bufio already panics on negative reads, it is not necessary to do
so as well. If the length is zero and for some reason no error is
returned, readBodyIdentity and appendBodyFixedSize now errors in these
cases.

Link: https://github.com/golang/go/blob/851f6fd61425c810959c7ab51e6dc86f8a63c970/src/bufio/bufio.go#L246

* fs: remove panic on negative reader count

When a negative count is reached when unregistering a reader, a panic is
thrown even though data-integrity is not at risk.

Replace the panic() with a simple clamp on the value to ensure the
value does not exceed it's expected lower bounds.

* server: remove panic in favour of a segfault

Panicking with "BUG: " obscures the error. As the segfault causes a
panic anyway, just let the chaos unfold.

* server: remove panic in favour of returning an error

Writing on a timed-out response is not endangering data integrity and
just fails.

* chore: add comments to all panics

* chore: fix minor typo
2023-03-30 03:38:28 +02:00
Oleksandr Redko e15a810a98 docs: fix grammar issues and typos in comments (#1492) 2023-02-13 10:43:44 +08:00
Oleksandr Redko 934f04e330 Refactor golangci-lint config and remove redundant nolints (#1486)
* Refactor golangci-lint config

- Use golangci-lint-action for GitHub workflow.
- Add additional golangci-lint run options.
- Remove unused nolint directives.

* Revert exclude-use-default option
2023-02-11 15:35:15 +08:00
Erik Dubbelboer dbf457ee66 Revert "feat: support mulit/range (#1398)" (#1446)
This reverts commit a468a7dd37.
2022-11-28 11:52:30 +01:00
byene0923 a468a7dd37 feat: support mulit/range (#1398)
* feat: support mulit/range

* fix:
1. lint code
2. add SetByteRanges method

* fix: reduce the test number of testFSSingleByteRange
2022-10-30 09:48:46 +01:00
Aoang a696949f6c Deprecate Go 1.15 (#1379)
* Dropping support for 1.15.

* Replaces Go 1.16 Deprecated functions

* Update test build flag

* Fix import sort and comment

* Update github.com/klauspost/compress to v1.15.9

https://github.com/klauspost/compress improved performance and changed Minimum version is 1.16, this should be the final supported release for Go 1.16 (https://github.com/klauspost/compress/commit/6d0019a95afa3221f7522d1f2eed0033b5e79470) .
2022-09-15 22:28:25 +03:00
Aoang ea6052464e Add Go 1.19 Support (#1355)
* Update Go Version to Go1.19.x And add cache

* Fix CI Line endings

* Update test CI Go Version to Go1.19.x And add cache

* Update Gosec Security Scanner CI to securego/gosec@v2.12.0

* Format comment

Go 1.19 adds support for links, lists, and clearer headings in doc comments. As part of this change, gofmt now reformats doc comments to make their rendered meaning clearer. See “Go Doc Comments” for syntax details and descriptions of common mistakes now highlighted by gofmt. As another part of this change, the new package go/doc/comment provides parsing and reformatting of doc comments as well as support for rendering them to HTML, Markdown, and text.

ref: https://tip.golang.org/doc/go1.19
ref: https://tip.golang.org/doc/comment

* Fix doc structure
2022-08-14 11:31:57 +02:00
mojatter f3513ccc59 Introduce FS.CompressRoot (#1331)
* Introduce FS.CompressRoot

* Avoid duplicated filepath.FromSlash

* Introduce filePathToCompressed

* Revert openIndexFile manually

* Join root and path, and then calls filepath.FromSlash
2022-07-10 10:07:18 +02:00
Sergey Ponomarev c9f43eaa1b Response.ContentEncoding(): store as field and avoid using Header.SetCanonical() (#1311)
* Response.ContentEncoding(): store as field

The CE is not so often used for plain APIs responses and even not so often used for static files and on the fly compression.
But still it should be checked each time.
Also having a dedicated field getter and setter simplifies code

* header.go Use shorter Response.setNonSpecial() and Request.setNonSpecial() methods instead of SetCanonical()

The change should improve performance because the setSpecialHeader() call is omitted.
As a downside on adding a new basic header field all putHeader() must be replaced with a direct getter and setter.
2022-06-05 15:47:59 +02:00
RW 66bc61ee64 Add an option to allow empty root in the fsHandler (#1299)
* Add an option to allow empty root in the fsHandler

this is necessary to restore the capabilities before the commit https://github.com/valyala/fasthttp/commit/c7576cc10cabfc9c993317a2d3f8355497bea156
and to allow further functionality to be docked from the outside which is not affected by setting the root dir afterwards

https://github.com/gofiber/fiber/pull/1882#issuecomment-1120832500

* Add an option to allow empty root in the fsHandler

this is necessary to restore the capabilities before the commit https://github.com/valyala/fasthttp/commit/c7576cc10cabfc9c993317a2d3f8355497bea156
and to allow further functionality to be docked from the outside which is not affected by setting the root dir afterwards

https://github.com/gofiber/fiber/pull/1882#issuecomment-1120832500

* Update fs.go

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>

* Update fs.go

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2022-05-16 12:33:47 +02:00
Mauro Leggieri c7576cc10c Added Windows support and removed some panics (#1264) 2022-04-09 15:38:51 +02:00
Erik Dubbelboer 7a5afddf5b Use %v for errors and %q for strings (#1262)
Mostly in tests.
2022-04-01 18:11:16 +02:00
Erik Dubbelboer 15262ecf3c Warn about unsafe ServeFile usage (#1228)
See: https://github.com/valyala/fasthttp/issues/1226
2022-03-03 08:51:13 +01:00
Erik Dubbelboer e9db537178 Use %w to wrap errors (#1175) 2021-12-13 09:41:34 +01:00
Erik Dubbelboer 931d0a4523 Fix lint 2021-11-04 13:24:40 +01:00
halst d613502912 use sync.map is better (#1145)
* use sync.map is better

* Use LoadOrStore
2021-11-04 13:01:58 +01:00
Erik Dubbelboer 3cec26d42d Allow stopping FS handler cleanup gorountine (#942)
* Allow stopping FS handler cleanup gorountine

* CleanStop
2021-02-06 10:22:14 +01:00
hex0x00 805af0ee73 Brotli support in FS handler. (#880)
* Add files via upload

* Update fs.go

* Add files via upload

* Update fs_test.go
2020-09-28 17:14:28 +02:00
Erik Dubbelboer 380f00bfdb Fixed bug which prevents cached FS files from being updated
Bug was introduced in previous "Fixed recompressing of stale files"
commit.
2020-06-12 21:47:32 +02:00
Erik Dubbelboer 2f28edba01 Fixed recompressing of stale files 2020-06-07 11:54:40 +02:00
RW 853abb31af 🐞 panic in fs.go #824 (#825)
Co-authored-by: wernerr <rene.werner@verivox.com>
2020-06-04 16:53:47 +02:00
Moritz Marquardt 5bd1b0cf2c Make FS return a redirect for directories without trailing slash (#802)
* Make FS return a redirect for directories without trailing slash

Fixes #792

* Add a test for the directory redirect

* Fix directory redirects for ServeFile

* Fix error message

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2020-05-18 18:30:13 +02:00
Erik Dubbelboer 32793db72d Run golangci-lint using a Github Action 2019-11-16 18:09:28 +01:00
Shulhan 9574c37fb8 Various changes regarding code readibility (#523)
* all: use sort.Strings when applicable

Basically, sort.Strings is the shortcut of Sort(StringSlice(a)) but its
more readable.

* all: replace string(bytes.Buffer.Bytes()) with bytes.Buffer.String()

Although its only occured on test files, it may be worth to simplified it.

* http_test: simplify strings.Index with strings.Contains

Both have the same O(n), but strings.Contains more readable on
if-condition.

* args: simplify if-condition check on boolean value

* all: simplify variable initialization

If we assign the variable after declaring it, we can simplify it using
":=" operator or "= value".
The reader can still known the type of variable from the struct name or
variable type before assignment operator.
2019-02-02 11:13:33 +00:00
Shulhan 4c53f113c5 all: pre-allocated slice with possible known size
This fix is based on suggestion of "prealloc" static analysis tool [1].

Per note of the tool's author suggestion, its recommended to allocate the
slice length/capability, if we known their possible size.  This is to
minimize "append" to re-allocate the slice underlying array.

[1] https://github.com/alexkohler/prealloc
2019-01-30 20:42:28 +01:00
Erik Dubbelboer d4f0cf56d8 Remove fasthttp.ByteBuffer
As advertised in https://github.com/valyala/fasthttp/commit/b5f96d4b4120bb1e09c23ac32baf21a14da4a71d
2018-10-01 14:15:29 +08:00
Erik Dubbelboer d53df67945 Fix Content-Type bug in FS
Fixes #417
2018-09-20 11:36:07 +08:00
Jerry Jacobs 6025a4a41c Allow overwrite of ContentType by caller of RequestCtx.ServeFile 2018-09-13 12:27:17 +08:00
Kirill Danshin dc5b83b915 fs/pathNotFound: do not overwrite user's status code
Signed-off-by: Kirill Danshin <k@guava.by>
2018-08-17 22:04:50 +03:00
Erik Dubbelboer e3fd87a866 Added PathNotFound handle func for handling 404.
See https://github.com/erikdubbelboer/fasthttp/pull/10
2018-08-17 15:51:44 +08:00
xPushkin f24d00fcc6 A lot of typo fixes 2017-10-08 13:30:35 +01:00
Aliaksandr Valialkin 30e92af08f Limit heap memory usage when compressing high number of concurrent responses
Previously each concurrent compression could allocate huge compression state
with the size up to 1Mb each. So 10K concurrent connections could result in
10Gb of compression state in the heap.

This CL limits the number of compression states among concurrent requests
when {Append,Write}{Gzip,Deflate}* functions are called to O(GOMAXPROCS).
These functions are used by CompressHandler* for non-streaming responses,
i.e. it should cover the majority of use cases.

Memory usage for 10K concurrent connections that compress responses drops
from 10Gb to 200Mb after this CL.
2017-05-17 14:45:31 +03:00
Aliaksandr Valialkin 204fed9187 Revert "Use standard compress packages until https://github.com/klauspost/compress/issues/64 is fixed"
The original issue has been fixed, so reverting.

This reverts commit 2f4876aaf2.
2016-10-20 18:02:21 +03:00
Aliaksandr Valialkin 2f4876aaf2 Use standard compress packages until https://github.com/klauspost/compress/issues/64 is fixed 2016-10-20 15:30:15 +03:00
Aliaksandr Valialkin b131f05f50 Revert "Use standard compress/* packages instead of github.com/klauspost/compress/*"
According to @klauspost, his packages are still faster than the standard packages.
See https://github.com/valyala/fasthttp/commit/a98191f43560ea2ddbbf848c1c727daeed2e39ae#commitcomment-19409416
for details.

This reverts commit a98191f435.
2016-10-13 14:57:35 +03:00
Aliaksandr Valialkin a98191f435 Use standard compress/* packages instead of github.com/klauspost/compress/*
The reasons are:
- @klauspost optimized standard packages in go1.7+
- This removes an external dependency from fasthttp
2016-10-13 13:01:51 +03:00