Open
Description
In order to permanently avoid the problem of #2396, we should start and switch to never return anonymous functions (closures) but return non-anonymous functions instead so no data is shared — never. For middlewares this might look as follows:
// New creates a new middleware handler
func New(config ...Config) fiber.Handler {
// Setup, etc.
// Return new handler
return newHandler(list, shared, data, here, config, etc)
}
func newHandler(list, shared, data, here, config, etc) func(c *fiber.Ctx) {
// Important: Never do anything in here before returning the closure.
return func(c *fiber.Ctx) {
// Code of handler as before, but without access to data of setup logic
}
}
Originally posted by @leonklingele in #2396 (comment)