Skip to content
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

Application singleton is not really a singleton. #1653

Open
twisted1919 opened this issue Apr 19, 2019 · 0 comments

Comments

Projects
None yet
2 participants
@twisted1919
Copy link

commented Apr 19, 2019

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:
Screenshot 2019-04-19 20 18 21
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:

func logger() buffalo.Logger {
	return actions.App().Options.Logger
}

And i guess this somehow affects what's going on. It's just a hunch though.

However, if instead of:

    func App() *buffalo.App {
        if app == nil { ... }
    }

i'm using sync.Once:

    var appOnce sync.Once
    func App() *buffalo.App {
        appOnce.Do(func() {  ...  })
    }

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.