From d19b893c63965ec61cd2117265eb74dd5ce4ed4a Mon Sep 17 00:00:00 2001 From: Oliver Maskery Date: Mon, 17 Jun 2024 08:26:13 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9A=20Doc:=20Update=20intro.md=20to=20?= =?UTF-8?q?make=20clear=20`fiber.Ctx`=20is=20not=20thread-safe.=20(#3014)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 📚 Update intro.md to make clear fiber.Ctx is not thread-safe. Closes #3012 * Update intro.md --------- Co-authored-by: RW --- docs/intro.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/intro.md b/docs/intro.md index d482df10..1e13c103 100644 --- a/docs/intro.md +++ b/docs/intro.md @@ -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!