Skip to content

Incorrect Mounting in RunHTTPServerOnAddr can Lead to Infinite Loop #74

Open
@yuyayang02

Description

@yuyayang02

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions