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

Incorrect Mounting in RunHTTPServerOnAddr can Lead to Infinite Loop #74

Open
qmstar0 opened this issue Feb 10, 2024 · 0 comments
Open

Comments

@qmstar0
Copy link

qmstar0 commented Feb 10, 2024

While studying the wild-workouts-go-ddd-example, I noticed a small issue in the RunHTTPServerOnAddr method within internal/common/server/http.go at line 24. The createHandler parameter is a function that requires using the provided router parameter and returning a http.Handler.

I observed that in the test cases and main.go file, the method passed as an argument is:

func(router chi.Router) http.Handler {
    return ports.HandlerFromMux(ports.NewHttpServer(app), router)
}

This function returns ports.HandlerFromMux(ports.NewHttpServer(app), router), where ports.HandlerFromMux
internally returns the router passed to it. In other words, the result obtained by createHandler(router) is the router itself,
processed and returned by the same router. This leads to a potential issue when executing the following code:

rootRouter.Mount("/api", createHandler(apiRouter))

It results in mounting the router under its own "/api" route, causing an infinite loop when recursively iterating over the child routes.

To address this, it may be necessary to revisit how the createHandler function is implemented or applied, ensuring that it does not lead to unintended recursive mounting of the router under its own route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant