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

Dynamic route not working if multiple static routes contain same prefix #386

Closed
mathisuniversal opened this issue Dec 7, 2021 · 2 comments
Labels

Comments

@mathisuniversal
Copy link

Describe the bug
A dynamic /{path} endpoint with a static /bar endpoint works fine. But if I add another one with /baz, requests to routes with a /ba prefix fail. This also occurs with other prefixes and if the static routes consist of more URL segments.

Your configuration file
Minimal example:

{
  "version": 2,
  "timeout": "3000ms",
  "cache_ttl": "300s",
  "output_encoding": "json",
  "name": "krakend-test",
  "endpoints": [
    {
      "endpoint": "/{static}",
      "backend": [
        {
          "host": []
        }
      ]
    },
    {
      "endpoint": "/bar",
      "backend": [
        {
          "host": []
        }
      ]
    },
    {
      "endpoint": "/baz",
      "backend": [
        {
          "host": []
        }
      ]
    }
  ]
}

Commands used
How did you start the software?

# Windows Power Shell:
docker pull devopsfaith/krakend@1.4.1
docker run -p 8080:8080 -v ${PWD}:/etc/krakend/ devopsfaith/krakend:1.4.1

# in another terminal:
curl http://localhost:8080/basomething

Expected behavior
I would expect /basomething to match the /{path} endpoint.

Logs

2021/12/07 13:29:58 http: panic serving 172.17.0.1:49082: invalid node type
goroutine 37 [running]:
net/http.(*conn).serve.func1(0xc000266f00)
        /usr/local/go/src/net/http/server.go:1824 +0x153
panic(0x2415d00, 0x2d84640)
        /usr/local/go/src/runtime/panic.go:971 +0x499
github.com/gin-gonic/gin.(*node).findCaseInsensitivePathRec(0xc000720c40, 0xc00074e0c4, 0xc, 0xc00055e000, 0x0, 0x80, 0x100000000, 0xc000702001, 0xc0005538c0, 0x0)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/tree.go:790 +0x109b
github.com/gin-gonic/gin.(*node).findCaseInsensitivePath(0xc000720c40, 0xc00074e0c4, 0xc, 0x1, 0xc, 0x203000, 0x2, 0x0)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/tree.go:597 +0xb6
github.com/gin-gonic/gin.redirectFixedPath(0xc000556100, 0xc000720c40, 0x1, 0xc00055c000)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/gin.go:557 +0x77
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc000882000, 0xc000556100)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/gin.go:498 +0x60d
github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc000882000, 0x2de4d10, 0xc00055a000, 0xc000556000)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/gin.go:445 +0x15c
net/http.serverHandler.ServeHTTP(0xc0001fec40, 0x2de4d10, 0xc00055a000, 0xc000556000)
        /usr/local/go/src/net/http/server.go:2887 +0xa3
net/http.(*conn).serve(0xc000266f00, 0x2ded2f0, 0xc0004a4140)
        /usr/local/go/src/net/http/server.go:1952 +0x8cd
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:3013 +0x39b
2021/12/07 13:29:58 http: panic serving 172.17.0.1:49086: invalid node type
goroutine 67 [running]:
net/http.(*conn).serve.func1(0xc0006c8000)
        /usr/local/go/src/net/http/server.go:1824 +0x153
panic(0x2415d00, 0x2d84640)
        /usr/local/go/src/runtime/panic.go:971 +0x499
github.com/gin-gonic/gin.(*node).findCaseInsensitivePathRec(0xc000720c40, 0xc000500064, 0xc, 0xc0009cc000, 0x0, 0x80, 0x100000000, 0xc000120101, 0xc00054f8c0, 0x0)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/tree.go:790 +0x109b
github.com/gin-gonic/gin.(*node).findCaseInsensitivePath(0xc000720c40, 0xc000500064, 0xc, 0x1, 0xc, 0x203000, 0x2, 0x0)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/tree.go:597 +0xb6
github.com/gin-gonic/gin.redirectFixedPath(0xc0009ca000, 0xc000720c40, 0x1, 0xc0009c8000)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/gin.go:557 +0x77
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc000882000, 0xc0009ca000)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/gin.go:498 +0x60d
github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc000882000, 0x2de4d10, 0xc0009c4000, 0xc0000b7a00)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/gin.go:445 +0x15c
net/http.serverHandler.ServeHTTP(0xc0001fec40, 0x2de4d10, 0xc0009c4000, 0xc0000b7a00)
        /usr/local/go/src/net/http/server.go:2887 +0xa3
net/http.(*conn).serve(0xc0006c8000, 0x2ded2f0, 0xc00004e140)
        /usr/local/go/src/net/http/server.go:1952 +0x8cd
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:3013 +0x39b

Additional context
I know the documentation states that colliding routes are not supported. But according to #325 it should work and there are no errors at startup.

@alombarte
Copy link
Member

Hi @mathisuniversal, the documentation says that you cannot have colliding routes and until KrakenD 2.0 this statement won't be removed from the documentation.

Although you can declare colliding routes on 1.4.1, they are still officially unsupported and there will be problems with endpoints sharing prefixes, as you have pointed out. See this issue: gin-gonic/gin#2959

Krakend 2.0 will either fix, document or provide a workaround to this issue.

@github-actions
Copy link

This issue was marked as resolved a long time ago and now has been automatically locked as there has not been any recent activity after it. You can still open a new issue and reference this link.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants