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
* Fix various Windows Github Action errors
These tests keep giving errors because Windows Actions are slower.
* Remove some timeouts
We don't need timeouts in all tests, only in the ones where we are
actually testing timeout logic.
* Flush buffered responses if we have to wait for the next request
Don't wait for the next request as this can take some time, instead
flush the outstanding responses already.
Fixes#1043
* Only peek 1 byte
Make sure old clients that send bogus \r\n still work.
See: https://github.com/golang/go/commit/bf5e19fbaf02b1b25fbe50c27ec301fe830a28d0
* Run go test on github actions
travis-ci.org has stopped.
See also: https://github.com/curl/curl/issues/7150
Downside: github actions don't support ppc64le
* Run less
* delete .travis.yml
* Remove travis + minor lint fixes
* Run test with go 1.16.X
* Fix min required go version
* Add go tip
* Update .github/workflows/security.yml
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
* http: refactor out crlf reading function
Make it a bit simpler and make it reusable.
* streaming: fix chunked stream test
This test is supposed to check for stream unchunking, but it's not really
effective with that because chunks created by createChunkedBody() get wrapped
into another chunk by writeBodyStream(), so we end up with chunkedBody in
request handler although what we really want is plain body.
Deduplicate test and benchmark also.
* streaming: fix Read interface
It wasn't actually compatible with io.Reader as io.Reader _never_ returns n >
len(p) while this function easily did that for chunked payloads confusing its
users:
panic: runtime error: slice bounds out of range [:528] with capacity 512
goroutine 562 [running]:
io.ReadAll(0x9f4380, 0xc0003be1a0, 0xc0004fcd80, 0x0, 0x0, 0xc00086bc30, 0x46f99b)
/usr/lib64/go/1.16/src/io/io.go:634 +0x205
io/ioutil.ReadAll(...)
/usr/lib64/go/1.16/src/io/ioutil/ioutil.go:27
github.com/valyala/fasthttp.getChunkedTestEnv.func1(0xc001fdc680)
/home/rik/dev/fasthttp/streaming_test.go:108 +0x6c
github.com/valyala/fasthttp.(*Server).serveConn(0xc000416d80, 0xa034e8, 0xc0004da880, 0x0, 0x0)
/home/rik/dev/fasthttp/server.go:2219 +0x12ee
github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc000148960, 0xc0003be160)
/home/rik/dev/fasthttp/workerpool.go:223 +0xba
github.com/valyala/fasthttp.(*workerPool).getCh.func1(0xc000148960, 0xc0003be160, 0x8b4ec0, 0xc0003be160)
/home/rik/dev/fasthttp/workerpool.go:195 +0x35
created by github.com/valyala/fasthttp.(*workerPool).getCh
/home/rik/dev/fasthttp/workerpool.go:194 +0x11f
It also returned len(p) in some cases where it read less than that.
* fix: Unexpected panic for PipelineClient
PipelineClient would panic when calling `Do` with a nil Response as
the second parm
This commit fixes the unexpected panic by checking nil first before
setting fields for Response
* Add tests to ensure nil resp is valid for PipelineClient