-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 [Bug]: RebuildTree randomly causing nil reference issue #3190
Comments
Have we changed our strategy? Is adding a route after the server start possible in v3, didn't know that. |
@ReneWerner87 Yes, it was added here with a big warning. #3074 |
Ok then its a bug. Seems that this method is not 100% thread safe. |
It is not, thus why the warning. Basically that last test hit the server while the route was being added to the Router. |
Or the access for the routing items is not thread safe, but adding a mutex here will slow down it for everyone. |
Yes correct. |
However, we could make a switch in the config called Then the others would not run slower and you could only use mutex in the routing process and also in rebuildRouting if this is set. |
@sujit-baniya Found the problem in your code, the handler being created inside your first handler is using the Change your code to this: package main
import (
"github.com/gofiber/fiber/v3"
)
func main() {
app := fiber.New()
app.Get("/", func(c fiber.Ctx) error {
app.Get("/hello", func(ctx fiber.Ctx) error {
// Use ctx not c here
return ctx.SendString("Hello, World 👋!")
})
app.RebuildTree()
return c.SendString("Added")
})
app.Listen(":3000")
} I added a comment where the issue was. |
Ah! ok... I'm attempting few more times before closing this issue. By the way, I was expecting this code to work but after visiting package main
import (
"github.com/gofiber/fiber/v3"
)
func main() {
app := fiber.New()
app.Get("/", func(c fiber.Ctx) error {
app.Get("/hello", func(ctx fiber.Ctx) error {
// Use ctx not c here
return ctx.SendString("Hello, World 👋!")
})
app.RebuildTree()
return c.SendString("Added")
})
app.Get("/updated", func(c fiber.Ctx) error {
app.Get("/hello", func(ctx fiber.Ctx) error {
// Use ctx not c here
return ctx.SendString("Bye, World 👋!")
})
app.RebuildTree()
return c.SendString("Updated")
})
app.Listen(":3000")
} |
@sujit-baniya You can't overwrite or remove routes. See #3098 |
Bug Description
Video:
Screen.Recording.2024-11-07.at.10.00.08.mov
In this code, I just tried to add a new route and rebuild the route stack. When trying to visit the newly added route, the error is thrown which is random in nature.
Error:
Error Code:
How to Reproduce
Steps to reproduce the behavior:
Run following code, at random there should be such error:
Expected Behavior
Application should have executed without any issue
Fiber Version
v3.0.0-beta.3
Code Snippet (optional)
Checklist:
The text was updated successfully, but these errors were encountered: