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

"no router to route request" (regex_priority is nil) #4254

Closed
mars opened this issue Jan 28, 2019 · 7 comments
Closed

"no router to route request" (regex_priority is nil) #4254

mars opened this issue Jan 28, 2019 · 7 comments
Labels
Milestone

Comments

@mars
Copy link
Contributor

mars commented Jan 28, 2019

For Kong version 1.0.0-1.0.2 configured with a Route with null/nil regex_priority, Kong throws a 500 error when receiving any request, logging the error (formatted for readability):

2019/01/28 22:47:06 [error] 54#0: *33046 [kong] handler.lua:687
  no router to route request (reason:
    /app/kong-runtime/share/lua/5.1/kong/runloop/handler.lua:116:
      attempt to compare nil with number), 
  client: x.x.x.x, 
  server: kong, 
  request: "GET /favicon.ico HTTP/1.1", 
  host: "xxxxx.example.com", 
  referrer: "https://xxxxx.example.com/"

Looking at Kong source location referenced in that error:

    sort(routes, function(r1, r2)
      r1, r2 = r1.route, r2.route
      if r1.regex_priority == r2.regex_priority then
        return r1.created_at < r2.created_at
      end
      return r1.regex_priority > r2.regex_priority  -- ← THIS IS LINE #116
    end)

So it seems to be routing code comparing route priorities.

I check the Postgres database to see what the route contains for that field:

-[ RECORD 2 ]--+-------------------------------------
id             | b4e8ae92-8e4c-40a4-87d9-98af04969da0
created_at     | 2019-01-28 23:07:05+00
updated_at     | 2019-01-28 23:07:05+00
service_id     | 36a43882-84ba-4fc8-aa2a-94569c4bf2b7
protocols      | {https}
methods        | 
hosts          | {mars-micro-wasabi.happ.host}
paths          | 
regex_priority |                                      ← THIS FIELD IS NULL
strip_path     | t
preserve_host  | f
name           | 
snis           | 
sources        | 
destinations   | 

The field is null.

So, it seems like at least one of these solutions would be good for Kong:

  • that handler/routing code should gracefully accept nil (treat like 0)
  • the data access layer should fill in a default of 0
  • the API should reject Route configuration requests that contain "regex_priority": null
@thibaultcha
Copy link
Member

@mars Thanks for the report! I can provide a patch asap.

@thibaultcha
Copy link
Member

@mars Btw, a Route's default regex_priority is 0 (as can be seen in its schema). How did you have this field set to NULL? An update, or a PUT maybe?

@thibaultcha
Copy link
Member

PR is #4255 - feel free to apply the patch on your end and verify that it solves the issue for you. Thanks again!

@thibaultcha thibaultcha added this to the 1.0.3 milestone Jan 29, 2019
@mars
Copy link
Contributor Author

mars commented Jan 29, 2019

Amazing! Thank you @thibaultcha I will build Kong on that PR and reply here with results.

My requests that set regex_priority → nil are from kevholditch/terraform-provider-kong, updating via PATCH & creating via POST.

thibaultcha added a commit that referenced this issue Jan 29, 2019
If Routes have `regex_priority` properties mixed between numbers and nil
(e.g. one Route was created with a default `regex_priority`, the other
was created with a purposefully NULL `regex_priority`, the comparison in
the router rebuild sorting of Routes would error out, because we are
comparing one Route's `nil` value against another Route's `number`.

Fix #4254
@mars
Copy link
Contributor Author

mars commented Jan 29, 2019

Using the PR's "fix/router-rebuild-no-regex-priority" branch I built Kong and while the 500 error is gone, it no longer matches requests for the route at all:

{"message":"no Route matched with those values"}

This route used to work, but have yet to discover why it's not matching now:

resource "kong_route" "wasabi_hostname" {
  protocols  = ["https"]
  paths      = ["/wasabi"]
  strip_path = true
  service_id = "${kong_service.wasabi.id}"
}

Will continue debugging tomorrow.

kikito pushed a commit that referenced this issue Jan 29, 2019
If Routes have `regex_priority` properties mixed between numbers and nil
(e.g. one Route was created with a default `regex_priority`, the other
was created with a purposefully NULL `regex_priority`, the comparison in
the router rebuild sorting of Routes would error out, because we are
comparing one Route's `nil` value against another Route's `number`.

Fix #4254
@mars
Copy link
Contributor Author

mars commented Jan 29, 2019

Now that the fix has been merged to master, I built Kong from master and now see that this is fixed ✅ 💯 Thank you for the fast action @thibaultcha 🤗

@forestgagnon
Copy link

FYI for those running Kong EE: I discovered that this bug is still present in some of the route-building logic in the latest enterprise edition (0.35-3). I've submitted a support ticket about this.

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

No branches or pull requests

3 participants