Skip to content

Commit

Permalink
πŸ“š Doc: Update intro.md to make clear fiber.Ctx is not thread-safe. (#…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
omaskery and ReneWerner87 committed Jun 17, 2024
1 parent 9caa11f commit d19b893
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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!

Expand Down

0 comments on commit d19b893

Please sign in to comment.