Commit Graph

1740 Commits

Author SHA1 Message Date
Kashiwa e2bb2e0d64 Improve performance of ParseUfloat (#1865)
* Improve performance of ParseUfloat function

Replaced `offset` handling logic with more efficient math.Pow10 based calculation.

goos: linux
goarch: amd64
pkg: github.com/valyala/fasthttp
cpu: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
              │   old.txt   │           new.txt           │
              │   sec/op    │   sec/op     vs base        │
ParseUfloat-8   44.22n ± 0%   31.06n ± 0%  -29.76% (n=50)

* fix: lint error return value is not checked

* Handling uint64 overflow issues

* Implement ParseUfloat by calling strconv.ParseFloat

* fix: lint error
v1.56.0
2024-09-22 15:46:29 +02:00
Kirill 7c9c003d1d fix: type assertion to perIPTLSConn instead of erroneous perIPConn (#1863) 2024-09-21 16:39:36 +02:00
Kashiwa 318e68ece3 Reduce the size of the Cookie by 32 bytes. (#1866)
Replace the field `bufKV` with two `[]byte` fields and remove the filed `buf`.

- Reduce Cookie from **224** to **192** bytes.
- In the benchmark tests, although there is no significant performance improvement, it theoretically reduces memory usage by **14.3%**.
2024-09-21 16:19:53 +02:00
dependabot[bot] 012887190c chore(deps): bump securego/gosec from 2.21.2 to 2.21.3 (#1870)
Bumps [securego/gosec](https://github.com/securego/gosec) from 2.21.2 to 2.21.3.
- [Release notes](https://github.com/securego/gosec/releases)
- [Changelog](https://github.com/securego/gosec/blob/master/.goreleaser.yml)
- [Commits](https://github.com/securego/gosec/compare/v2.21.2...v2.21.3)

---
updated-dependencies:
- dependency-name: securego/gosec
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-21 16:12:01 +02:00
Kashiwa 5745601565 Represent stateName by []string instead of map (#1871) 2024-09-21 16:11:46 +02:00
Sigmund Xia 夏天睿 65e989e8b8 Fix improper memory reuse in NewFastHTTPHandler (#1860)
* add test which will cause error

* rename test

* fix improper memory reuse in NewFastHTTPHandler

* move deep copy from VisitAll to f

* copy value string only for cookie
2024-09-10 20:05:52 +02:00
newacorn 74864cbda9 Revert "Using atomic instead of mutex and delete scratch slice" (#1846)
* Remove a redundant field and clarify the comments.

* Revert "Using atomic instead of mutex and delete scratch slice (#1833)"

This reverts commit 19c50cdc44.
2024-09-10 18:48:26 +02:00
dependabot[bot] 1d8ad873d1 chore(deps): bump securego/gosec from 2.21.1 to 2.21.2 (#1861)
Bumps [securego/gosec](https://github.com/securego/gosec) from 2.21.1 to 2.21.2.
- [Release notes](https://github.com/securego/gosec/releases)
- [Changelog](https://github.com/securego/gosec/blob/master/.goreleaser.yml)
- [Commits](https://github.com/securego/gosec/compare/v2.21.1...v2.21.2)

---
updated-dependencies:
- dependency-name: securego/gosec
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-10 18:15:47 +02:00
Erik Dubbelboer c3050516d9 Fix lint and security issues
gosec was failing after the last update introduced some new checks.
2024-09-07 15:22:05 +02:00
dependabot[bot] 7699fc9151 chore(deps): bump securego/gosec from 2.20.0 to 2.21.1 (#1855)
Bumps [securego/gosec](https://github.com/securego/gosec) from 2.20.0 to 2.21.1.
- [Release notes](https://github.com/securego/gosec/releases)
- [Changelog](https://github.com/securego/gosec/blob/master/.goreleaser.yml)
- [Commits](https://github.com/securego/gosec/compare/v2.20.0...v2.21.1)

---
updated-dependencies:
- dependency-name: securego/gosec
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-06 10:30:22 +02:00
dependabot[bot] bd3f816289 chore(deps): bump golang.org/x/net from 0.28.0 to 0.29.0 (#1857)
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.28.0 to 0.29.0.
- [Commits](https://github.com/golang/net/compare/v0.28.0...v0.29.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-06 10:30:02 +02:00
dependabot[bot] fe972df464 chore(deps): bump golang.org/x/crypto from 0.26.0 to 0.27.0 (#1858)
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.26.0 to 0.27.0.
- [Commits](https://github.com/golang/crypto/compare/v0.26.0...v0.27.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-06 10:23:34 +02:00
newacorn 4616630d57 Remove a redundant field and clarify the comments. (#1851) 2024-09-01 22:39:37 +02:00
newacorn b33e869e2e Another implementation of RetryIfErr (#1850)
* Support for delayed retry logic
* Support for resetting the request timeout before retrying
* Users can decide whether to retry based on the request error and the number of retries.
Estimating the time required for a request to complete is relatively straightforward, but when retries are factored in, it becomes challenging to gauge this time accurately.
2024-09-01 09:17:10 +02:00
Erik Dubbelboer d331a713fe Fix some benchmarks
%q instead of %s made the request invalid and makes some of our
benchmarks hang.
2024-08-31 15:04:15 +02:00
newacorn d5c7d8953d fix: The client write operation did not immediately return upon encountering an RST packet. (#1849)
The current client implementation does not immediately return when encountering an RST packet while sending a request, but instead ignores it. This behavior is inconsistent with the net/http package and does not make logical sense.
2024-08-31 14:52:13 +02:00
newacorn d31f4ef7d5 When StreamRequestBody is set to true, we cannot safely release br. (#1844)
For example, when using chunked encoding, it's possible that `br` has only read the request headers.
2024-08-31 14:41:54 +02:00
newacorn 3aa972e2fc Fix issues with tests interfering with each other in certain situations. (#1842)
In some cases, the goroutines started by one test do not terminate smoothly before the next round of tests begins, causing interference between tests.

Performance Impact: This results in test completion times not increasing linearly with the count value.

Correctness Impact: It affects the accuracy of memory allocation test cases.
2024-08-31 14:27:05 +02:00
newacorn f789432e77 Fix potential data race reports when the -race flag is enabled. (#1847)
The `testClientDoTimeoutError` and `testClientGetTimeoutSuccess` test function does not immediately return or fatal when the test fails. Instead, it continues to stringify the byte slice that was passed as the `dst` parameter to the `Client.GetTimeout` method. If the test fails due to a timeout, the request may still be ongoing, and there might be a data race between writing to `dst` and the stringification operation.
2024-08-31 14:26:07 +02:00
newacorn c15489d7f5 Make the tests complete earlier. (#1848)
Reduce the test duration to 36% of the original time.
2024-08-31 14:25:11 +02:00
newacorn b0ea03f70a Fix Different request paths share the same fs cache is some cases. (#1843)
Currently, the implementation may result in shared fs cache between requests for dir and dir/.
2024-08-31 14:21:51 +02:00
NikoMalik 19c50cdc44 Using atomic instead of mutex and delete scratch slice (#1833)
* using atomic instead of mutex and delete scratch slice

* optimize struct

* fix default bool

* escape data race

* avoid the momentary change of wp.workersCount.

* removed unused tail (for now)

* little fixes

* fixed allocations

This option immediately exits the loop when the maximum number of vorkers is reached, rather than creating a new vorker if the limit is reached. This reduces the frequency of unnecessary operations and potential locks in sync.Pool

* Update for linter workerpool.go

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

* Update for lint#2 workerpool.go

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

* Update for lint#3 workerpool.go

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

* Update for lint#4 workerpool.go

* eliminating potential data races

---------

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2024-08-25 17:03:05 +02:00
Kashiwa 25c52d7034 Make RetryIfFunc handle request errors (#1818)
* Make RetryIfFunc handle request errors.

* Replace interface{} to any

* Add field RetryIfErr to fix issue 1744

* Fix linter error
2024-08-25 16:14:02 +02:00
newacorn 6ed7f6bbf7 Add a multifunctional Dialer struct. (#1829)
Add a multifunctional `Dialer` struct and reimplement the function API

Reimplement the existing function interfaces of the fasthttpproxy package through Dialer. Refactor Dialer.GetDialFunc to ensure that its performance is comparable to the original function interfaces when the proxy does not change with the request address.
2024-08-24 12:46:01 +02:00
Erik Dubbelboer 0f84e656c2 Remove support for go 1.19 and 1.20, and add support for 1.23 (#1837) 2024-08-23 21:56:27 +02:00
newacorn 43c7b83ee5 We cannot avoid continuing to call SetReadDeadline and similar methods after the connection is closed. (#1835)
In the current implementation, there are several places where it's assumed that SetReadDeadline and similar functions logically won't affect a closed connection. However, these assumptions may not hold in certain specific situations. Therefore, instead of asserting that such errors will never occur, simply return the errors encountered during the execution of these methods.
2024-08-21 22:42:09 +02:00
newacorn d29a2b90a6 Add a dedicated cache container for the zstd compression algorithm (#1828)
Add a dedicated cache container for the zstd compression algorithm to prevent discrepancies between the response content and the implied Content-Encoding in certain scenarios.Fix: https://github.com/valyala/fasthttp/issues/1827#issue-2459271452
2024-08-20 23:25:02 +02:00
newacorn 5cc0ea1ec3 Fix the MaxConns semaphore issue in HostClient. (#1831)
Fix the MaxConns semaphore issue in HostClient.

Currently, the conns length and connsCount count in HostClient do not correctly implement the MaxConns semaphore mechanism.
This fix ensures that the waiter wake-up chain does not break.
2024-08-20 23:24:01 +02:00
newacorn 3cdc6f124a TestHostClientMaxConnWaitTimeoutError test case sometimes fails (#1832)
The current implementation makes some incorrect assumptions about observing changes in the state of wantConn.
2024-08-20 23:23:43 +02:00
Erik Dubbelboer df8335f9ab A response without a body can't have trailers (#1825) 2024-08-20 23:10:04 +02:00
Kashiwa 9df444bdd2 Reduce the size of ResponseHeader and RequestHeader (#1826)
* Reduce sizeof ResponseHeader and RequestHeader

+ Reduce ResponseHeader from 320 to 312 bytes
+ Reduce RequestHeader from 360 to 352 bytes
+ In the benchmark tests, although there is no significant performance improvement, it theoretically reduces memory usage by 2.2% to 2.5%.

* Remove redundant comment
2024-08-20 23:02:30 +02:00
newacorn a1db411cc2 StreamRequestBody shouldn't read more data than actual need. (#1819)
* The StreamRequestBody should not read content beyond what is required.

The StreamRequestBody feature on the server side should not read content that does not belong to the current request body.This is more logical and consistent with the result of not using the StreamRequestBody feature.Fixes: https://github.com/valyala/fasthttp/issues/1816.

* Update server_test.go

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

* Update http.go

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

---------

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2024-08-11 15:35:28 +02:00
dependabot[bot] 38a91cda6f chore(deps): bump golang.org/x/sys from 0.23.0 to 0.24.0 (#1823)
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.23.0 to 0.24.0.
- [Commits](https://github.com/golang/sys/compare/v0.23.0...v0.24.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-08-10 11:23:10 +02:00
dependabot[bot] 9fe0bc2e6f chore(deps): bump golang.org/x/net from 0.27.0 to 0.28.0 (#1821)
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.27.0 to 0.28.0.
- [Commits](https://github.com/golang/net/compare/v0.27.0...v0.28.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-08-07 17:12:11 +02:00
dependabot[bot] 85ca45ef90 chore(deps): bump golang.org/x/crypto from 0.25.0 to 0.26.0 (#1820)
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.25.0 to 0.26.0.
- [Commits](https://github.com/golang/crypto/compare/v0.25.0...v0.26.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-08-07 17:01:17 +02:00
Juan Calderon-Perez 1fb3453165 Use Named Fields and Align Structures to Reduce Memory Usage (#1814)
* Use Named fields and Align Structures to Reduce Memory Usage

* Remove extra spaces
2024-08-02 22:26:52 +02:00
Juan Calderon-Perez bb0c8dd79c Replace custom AppendUint with strconv.AppendUint (#1813)
* Use strconv.AppendInt

* Replace AppendInt with AppendUint

* Fix typo
2024-07-31 21:59:52 +02:00
Kashiwa ed6a27a88e Fix header parser (#1808) (#1810)
* Fix RequestHeader parser (#1808)

When FastHTTP receives a header value suffixed or prefixed with tabs, they should be stripped.

* Remove redundant code

* Add test for header parser including tabs (#1808)
2024-07-28 11:16:14 +02:00
Erik Dubbelboer 0324e8d2a2 Make sure removed/resetted user valeus get garbage collected
Since our userData slice isn't shrunk when we delete values, it can
still keep pointing to things that have been removed. Set these pointers
to nil so that the key and value can be garbage collected.

Fixes https://github.com/valyala/fasthttp/issues/1812
2024-07-28 11:06:17 +02:00
byte0o a7d488a91c Fix possible race condition on request ctx done #1662 (#1806)
* Fix possible race condition on request ctx done #1662

* Fix possible race condition on request ctx done #1662

* Fix Comment

* fix remove the use of lock

* fix remove Comment
2024-07-23 21:15:57 +02:00
Kashiwa 86c7e844f4 Optimize struct field order to reduce memory usage (#1809)
1. Reduce RequestHeader from 368 bytes to 360 bytes
2. Reduce Request from 816 bytes to 800 bytes
3. Reduce Response from 432 bytes to 416 bytes
4. Reduce Client from 312 bytes to 288 bytes
5. Reduce HostClient from 416 bytes to 392 bytes
6. Reduce PipelineClient from 176 bytes to 168 bytes
7. Reduce pipelineConnClient from 216 bytes to 208 bytes
8. Reduce Cookie from 232 bytes to 224 bytes
9. Reduce FS from 184 bytes to 160 bytes
10. Reduce fsHandler from 168 bytes to 160 bytes
11. Reduce ResponseHeader from 328 bytes to 320 bytes
12. Reduce headerScanner from 128 bytes to 120 bytes
13. Reduce TCPDialer from 104 bytes to 96 bytes
14. Reduce workerPool from 152 btyes to 144 btyes
2024-07-20 19:20:26 +02:00
Erik Dubbelboer 7760a5b506 Validate request method
Use the same validation as net/http.

Fixes https://github.com/valyala/fasthttp/issues/1803
2024-07-14 09:43:40 +02:00
dependabot[bot] a032ec91b1 chore(deps): bump golang.org/x/net from 0.26.0 to 0.27.0 (#1801)
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.26.0 to 0.27.0.
- [Commits](https://github.com/golang/net/compare/v0.26.0...v0.27.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-07-08 08:31:03 +02:00
dependabot[bot] 48359c7be3 chore(deps): bump golang.org/x/crypto from 0.24.0 to 0.25.0 (#1802)
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.24.0 to 0.25.0.
- [Commits](https://github.com/golang/crypto/compare/v0.24.0...v0.25.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-07-08 07:44:40 +02:00
dependabot[bot] 3e028c69cc chore(deps): bump golang.org/x/sys from 0.21.0 to 0.22.0 (#1800)
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.21.0 to 0.22.0.
- [Commits](https://github.com/golang/sys/compare/v0.21.0...v0.22.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-07-05 17:07:12 +02:00
Erik Dubbelboer b4c0b2b47d Validate header values (#1796)
* Validate header values

Fixes https://github.com/valyala/fasthttp/issues/1794

* Don't allow empty header keys

And improve error handling for bad headers.
2024-07-03 10:04:04 +02:00
Sniper91 21b235d033 add timeout to proxy connection reading and writing (#1791)
Co-authored-by: kalmanzhao <kalmanzhao@tencent.com>
2024-06-19 11:19:46 +02:00
dependabot[bot] b06f4e21d9 chore(deps): bump securego/gosec from 2.19.0 to 2.20.0 (#1776)
Bumps [securego/gosec](https://github.com/securego/gosec) from 2.19.0 to 2.20.0.
- [Release notes](https://github.com/securego/gosec/releases)
- [Changelog](https://github.com/securego/gosec/blob/master/.goreleaser.yml)
- [Commits](https://github.com/securego/gosec/compare/v2.19.0...v2.20.0)

---
updated-dependencies:
- dependency-name: securego/gosec
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
v1.55.0
2024-06-14 09:39:33 +02:00
dependabot[bot] 6a7f259017 chore(deps): bump golang.org/x/net from 0.23.0 to 0.26.0 (#1788)
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.23.0 to 0.26.0.
- [Commits](https://github.com/golang/net/compare/v0.23.0...v0.26.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-14 09:39:01 +02:00
dependabot[bot] 7de6a26de7 chore(deps): bump golang.org/x/crypto from 0.21.0 to 0.24.0 (#1787)
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.21.0 to 0.24.0.
- [Commits](https://github.com/golang/crypto/compare/v0.21.0...v0.24.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-14 09:28:08 +02:00