📚 Doc: Update intro.md to make clear `fiber.Ctx` is not thread-safe. (#3014)

* 📚 Update intro.md to make clear fiber.Ctx is not thread-safe.

Closes #3012

* Update intro.md

---------

Co-authored-by: RW <rene@gofiber.io>
pull/3032/head
Oliver Maskery 2024-06-17 08:26:13 +01:00 committed by GitHub
parent 9caa11fd71
commit d19b893c63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 3 deletions

View File

@ -21,9 +21,12 @@ go get github.com/gofiber/fiber/v3
```
### Zero Allocation
Some values returned from **fiber.Ctx** are **not** immutable by default.
Because fiber is optimized for **high-performance** care is needed when using **fiber.Ctx**:
Because fiber is optimized for **high-performance**, values returned from **fiber.Ctx** are **not** immutable by default and **will** be re-used across requests. As a rule of thumb, you **must** only use context values within the handler, and you **must not** keep any references. As soon as you return from the handler, any values you have obtained from the context will be re-used in future requests and will change below your feet. Here is an example:
- Some values returned from **fiber.Ctx** are **not** immutable by default, and **will** be re-used across requests.
- **fiber.Ctx** is **not** thread-safe and **must not** be accessed concurrently by multiple goroutines, the immutable setting **does not** change this.
As a rule of thumb, you **must** only use context values within the handler, and you **must not** keep any references. As soon as you return from the handler, any values you have obtained from the context will be re-used in future requests and will change below your feet. Here is an example:
```go
func handler(c fiber.Ctx) error {
@ -70,7 +73,7 @@ app := fiber.New(fiber.Config{
})
```
For more information, please check [**\#426**](https://github.com/gofiber/fiber/issues/426) and [**\#185**](https://github.com/gofiber/fiber/issues/185).
For more information, please check [**\#426**](https://github.com/gofiber/fiber/issues/426), [**\#185**](https://github.com/gofiber/fiber/issues/185) and [**\#3012**](https://github.com/gofiber/fiber/issues/3012).
### Hello, World!