* 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
The return value of normalizePath should be a reusable []byte.
Returning strSlash could cause the strSlash constant to be reused and
resulted in very weird behavior. This specific case of normalizePath
almost never happens which made it even harder to spot.
The race detector on Windows was the only clue that something was
happening:
WARNING: DATA RACE
Write at 0x000001d082e3 by goroutine 446:
github.com/valyala/fasthttp.addLeadingSlash()
D:/a/fasthttp/fasthttp/uri_windows.go:8 +0xa5
github.com/valyala/fasthttp.normalizePath()
D:/a/fasthttp/fasthttp/uri.go:343 +0xbd
github.com/valyala/fasthttp.(*URI).parse()
D:/a/fasthttp/fasthttp/uri.go:314 +0x1606
github.com/valyala/fasthttp.(*URI).Parse()
D:/a/fasthttp/fasthttp/uri.go:266 +0xb3
github.com/valyala/fasthttp.testURIPathNormalize()
D:/a/fasthttp/fasthttp/uri_test.go:195 +0x47
github.com/valyala/fasthttp.TestURIPathNormalize()
D:/a/fasthttp/fasthttp/uri_test.go:176 +0x38e
testing.tRunner()
C:/hostedtoolcache/windows/go/1.15.15/x64/src/testing/testing.go:1123 +0x202
Previous read at 0x000001d082e3 by goroutine 332:
runtime.slicecopy()
C:/hostedtoolcache/windows/go/1.15.15/x64/src/runtime/slice.go:246 +0x0
github.com/valyala/fasthttp.(*RequestHeader).AppendBytes()
D:/a/fasthttp/fasthttp/header.go:1726 +0x24d
github.com/valyala/fasthttp.(*RequestHeader).Header()
D:/a/fasthttp/fasthttp/header.go:1698 +0x84
github.com/valyala/fasthttp.(*RequestHeader).Write()
D:/a/fasthttp/fasthttp/header.go:1682 +0x10f
github.com/valyala/fasthttp.(*Request).Write()
D:/a/fasthttp/fasthttp/http.go:1370 +0x1ab
github.com/valyala/fasthttp.testRequestSuccess()
D:/a/fasthttp/fasthttp/http_test.go:1788 +0x32a
github.com/valyala/fasthttp.TestRequestSuccess()
D:/a/fasthttp/fasthttp/http_test.go:1678 +0x2dd
testing.tRunner()
C:/hostedtoolcache/windows/go/1.15.15/x64/src/testing/testing.go:1123 +0x202
- Some tests can't be run in parallel.
- `URI` had a pointer to `RequestHeader` which was updated with
`RequestHeader.CopyTo` which resulted in the URI pointing to the wrong
`RequestHeader` causing bugs and race conditions.
The only reason `URI` contained a pointer to `RequestHeader` was to delay the
call to `RequestHeader.Host()` until really needed. But these days instead
of parsing all headers, `RequestHeader.Host()` uses
`RequestHeader.peekRawHeader()` which is rather fast. So we can remove the
pointer in `URI` and completely decouple the two structs improving code
quality and fixing the bug.
For some reason this results in faster code on average as well:
benchmark old ns/op new ns/op delta
BenchmarkClientGetEndToEnd1Inmemory-8 1189 1369 +15.14%
BenchmarkClientGetEndToEnd10Inmemory-8 1143 1161 +1.57%
BenchmarkClientGetEndToEnd100Inmemory-8 1228 1236 +0.65%
BenchmarkClientGetEndToEnd1000Inmemory-8 1213 1213 +0.00%
BenchmarkClientGetEndToEnd10KInmemory-8 1362 1350 -0.88%
BenchmarkClientEndToEndBigResponse1Inmemory-8 139967 130070 -7.07%
BenchmarkClientEndToEndBigResponse10Inmemory-8 142233 131809 -7.33%
BenchmarkServerGet1ReqPerConn-8 1726 1593 -7.71%
BenchmarkServerGet2ReqPerConn-8 882 927 +5.10%
BenchmarkServerGet10ReqPerConn-8 440 436 -0.91%
BenchmarkServerGet10KReqPerConn-8 341 339 -0.59%
BenchmarkServerPost1ReqPerConn-8 1728 1706 -1.27%
BenchmarkServerPost2ReqPerConn-8 968 963 -0.52%
BenchmarkServerPost10ReqPerConn-8 506 505 -0.20%
BenchmarkServerPost10KReqPerConn-8 424 420 -0.94%
BenchmarkServerGet1ReqPerConn10KClients-8 1117 1051 -5.91%
BenchmarkServerGet2ReqPerConn10KClients-8 565 514 -9.03%
BenchmarkServerGet10ReqPerConn10KClients-8 390 387 -0.77%
BenchmarkServerGet100ReqPerConn10KClients-8 355 348 -1.97%
BenchmarkServerHijack-8 339 348 +2.65%
BenchmarkServerMaxConnsPerIP-8 326 325 -0.31%
BenchmarkServerTimeoutError-8 24355 24180 -0.72%