Skip to content

bug: Generates lot of useless logs when cookie not found #4516

Description

@slene

Issue description

Environment

  • apisix version (cmd: apisix version): 2.6
  • OS (cmd: uname -a): centos 7.8

Minimal test code / Steps to reproduce the issue

{
  "uris": [
    "/*"
  ],
  "name": "route",
  "methods": [
    "GET"
  ],
  "vars": [
    [
      "cookie_upstream",
      "==",
      "dev"
    ]
  ],
  "status": 1
}

When cookie cookie_upstream not found.

2021/07/01 19:30:06 [warn] 46#46: *2782 [lua] ctx.lua:157: __index(): failed to fetch cookie value by key: cookie_upstream error: nil, client: 127.0.0.1, server: _, request: "GET / HTTP/1.1", host: "localhost:9181"

When cookie header not exists.

2021/07/01 19:38:50 [warn] 46#46: *19719 [lua] ctx.lua:157: __index(): failed to fetch cookie value by key: cookie_upstream error: no cookie found in the current request, client: 127.0.0.1, server: _, request: "GET / HTTP/1.1", host: "localhost:9181"

It generates a lot of useless logs. If this is unexpected, I can submit a pr.

             elseif core_str.has_prefix(key, "cookie_") then
                 local cookie = t.cookie
-                if cookie then
+                if cookie and ngx.var.http_cookie then
                     local err
                     val, err = cookie:get(sub_str(key, 8))
-                    if not val then
+                    if err then
                         log.warn("failed to fetch cookie value by key: ",
                                  key, " error: ", err)
                     end

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions