-
-
Notifications
You must be signed in to change notification settings - Fork 579
Application singleton is not really a singleton. #1653
Comments
Indeed, this issue ( However, it will not happen frequently (actually not happen in most case) since our scaffold also has But I am not sure how it happened... if the user-defined I think we can improve the scaffolded [1] http://gobuffalo.io/documentation/guides/goth/#example-usage |
We should still make sure that the code generated with The generated var app *buffalo.App
func App() *buffalo.App {
if app == nil {
app = buffalo.New(buffalo.Options{
Env: ENV,
SessionName: "_buffalo_session",
})
// **SNIP**
}
return app should be var app *buffalo.App
var appInit sync.Once
func App() *buffalo.App {
appInit.Do(func() {
app = buffalo.New(buffalo.Options{
Env: ENV,
SessionName: "_buffalo_session",
})
// **SNIP**
})
return app
} I just haven't had time yet to update the necessary templates in the gobuffalo cli and write a fixer for it. |
Yeah, I fully agree. Having a possible bug in the generated code for the user is not a good thing. I think adding that sync could be fine. Also, at the same time, I am curious about what made this very edge case happen. As described above, |
Description
It seems that the application singleton is not really a singleton, or something weird happens with my app.
If you take a look at:
you will see how some of my routes are registered twice.
I have a hunch this happens because in my app, i am also running a udp server, and inside it i defined a logger function like:
And i guess this somehow affects what's going on. It's just a hunch though.
However, if instead of:
i'm using
sync.Once
:Then my issue goes away, no more duplicate routes.
Steps to Reproduce the Problem
See above.
Expected Behavior
I expect to see unique routes.
Actual Behavior
I see duplicate routes
The text was updated successfully, but these errors were encountered: