Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

bug: runtime error: /usr/local/openresty/lualib/resty/core/request.lua:116: bad argument #1 to 'lower' (string expected, got nil) #7276

Closed
hongbinhsu opened this issue Jun 18, 2022 · 11 comments · Fixed by #7531
Assignees
Labels
bug Something isn't working

Comments

@hongbinhsu
Copy link

Current Behavior

When use docker apache/apisix:2.13.1-alpine or apache/apisix:2.14.1-alpine

"GET /test/api/data/page/layout?name=home_v1&platform=app"

请求时报

[error] 46#46: *8041 lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/core/request.lua:116: bad argument #1 to 'lower' (string expected, got nil)

use docker apache/apisix:2.12.1-alpine 版本正常

Expected Behavior

No response

Error Logs

No response

Steps to Reproduce

  1. Run docker apache/apisix:2.13.1-alpine or apache/apisix:2.14.1-alpine
  2. GET 正则转发后并且带有get参数的接口时,报500错误
    [error] 46#46: *8041 lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/core/request.lua:116: bad argument change: added doc of how to load plugin. #1 to 'lower' (string expected, got nil)

Environment

  • APISIX version (run apisix version): apache/apisix:2.13.1-alpine or apache/apisix:2.14.1-alpine
  • Operating system (run uname -a): centos 7
  • OpenResty / Nginx version (run openresty -V or nginx -V): /
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info): bitnami/etcd:latest
  • APISIX Dashboard version, if relevant: /
  • Plugin runner version, for issues related to plugin runners: /
  • LuaRocks version, for installation issues (run luarocks --version): /
@hongbinhsu hongbinhsu changed the title bug: [error] 46#46: *8041 lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/core/request.lua:116: bad argument #1 to 'lower' (string expected, got nil) bug: runtime error: /usr/local/openresty/lualib/resty/core/request.lua:116: bad argument #1 to 'lower' (string expected, got nil) Jun 18, 2022
@tokers
Copy link
Contributor

tokers commented Jun 19, 2022

@hongbinhsu Hi, what are the route and upstream configurations to match your request?

@hongbinhsu
Copy link
Author

@hongbinhsu Hi, what are the route and upstream configurations to match your request?

upstream configurations:IP:8080/page/layout?name=home_v1&platform=app

route configurations:
Path rewriting:Regular rewriting
Regular expression:^ /test/api/data/(.*)$
Forwarding path:/$1

@tokers
Copy link
Contributor

tokers commented Jun 19, 2022

@hongbinhsu Hi, what are the route and upstream configurations to match your request?

upstream configurations:IP:8080/page/layout?name=home_v1&platform=app

route configurations: Path rewriting:Regular rewriting Regular expression:^ /test/api/data/(.*)$ Forwarding path:/$1

Could you just show the specific APISIX Route and Upstream objects?

@hongbinhsu
Copy link
Author

@hongbinhsu Hi, what are the route and upstream configurations to match your request?

upstream configurations:IP:8080/page/layout?name=home_v1&platform=app
route configurations: Path rewriting:Regular rewriting Regular expression:^ /test/api/data/(.*)$ Forwarding path:/$1

Could you just show the specific APISIX Route and Upstream objects?

Same configuration,use version 2.12.1 is success,when upgraded to 2.13.0 2.13.1 2.14.0

Wait a minute, I'm trying to use more versions

@tzssangglass
Copy link
Member

2. lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/core/request.lua:116

can you show the full function stacks?

@tzssangglass
Copy link
Member

The test cases I tried to reproduce

use t::APISIX 'no_plan';

add_block_preprocessor(sub {
    my ($block) = @_;

    my $http_config = $block->http_config // <<_EOC_;

    server {
        listen 1986;
        server_tokens off;

        location / {
            content_by_lua_block {
                local core = require("apisix.core")
                core.log.info("uri: ", ngx.var.request_uri)
                ngx.say("hello world")
            }
        }
    }
_EOC_

    $block->set_value("http_config", $http_config);

    if (!$block->request) {
        $block->set_value("request", "GET /t");
    }

    if (!$block->error_log && !$block->no_error_log) {
        $block->set_value("no_error_log", "[error]\n[alert]");
    }
});

no_long_string();
no_root_location();
log_level("info");
run_tests;

__DATA__

=== TEST 1: set route
--- config
    location /t {
        content_by_lua_block {
            local t = require("lib.test_admin").test
            local code, body = t('/apisix/admin/routes/1',
                ngx.HTTP_PUT,
                [[{
                    "plugins": {
                        "proxy-rewrite": {
                             "regex_uri":  ["^/test/api/data/(.*)", "/$1"]
                        }
                    },
                    "upstream": {
                        "nodes": {
                            "127.0.0.1:1986": 1
                        },
                        "type": "roundrobin"
                    },
                    "uri": "/test/api/data/*"
                }]]
                )

            if code >= 300 then
                ngx.status = code
                ngx.say(body)
            end
            ngx.say(body)
        }
    }
--- response_body
passed



=== TEST 2: hit
--- request
GET /test/api/data/page/layout?name=home_v1&platform=app
--- response_body
hello world

it works well.

@dickens7
Copy link
Contributor

I ran into a similar problem with this PR #6502

The following configuration can reproduce this problem

Route

{
  "uri": "/*",
  "plugins": {
    "key-auth": {
      "disable": false
    }
  },
  "upstream": {
    "nodes": [
      {
        "host": "127.0.0.1",
        "port": 9080,
        "weight": 1
      }
    ],
    "type": "roundrobin",
    "scheme": "http",
    "pass_host": "pass",
  },
  "status": 1
}

Consumer

{
  "username": "test",
  "plugins": {
    "ip-restriction": {
      "disable": false,
      "whitelist": [
        "127.0.0.1"
      ]
    },
    "key-auth": {
      "disable": false,
      "key": "xxxxxx"
    }
  }
}

Error Log

2022/07/24 02:42:30 [error] 48#48: *18767 lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/core/request.lua:116: bad argument #1 to 'lower' (string expected, got nil)
stack traceback:
coroutine 0:
        [C]: in function 'lower'
        /usr/local/openresty/lualib/resty/core/request.lua:116: in function '__index'
        /usr/local/apisix/apisix/core/request.lua:92: in function 'header'
        /usr/local/apisix/apisix/plugins/key-auth.lua:88: in function 'phase_func'
        /usr/local/apisix/apisix/plugin.lua:746: in function 'run_plugin'
        /usr/local/apisix/apisix/init.lua:478: in function 'http_access_phase'
        access_by_lua(nginx.conf:364):2: in main chunk, client: 172.22.0.3, server: _, request: "GET / HTTP/1.1", host: "172.22.0.5"

@dickens7
Copy link
Contributor

@hongbinhsu Is your route associated with consumer, and consumer has more than one plug-in

@tzssangglass
Copy link
Member

The following configuration can reproduce this problem

Which version of APISIX are you using? Can reproduce it on the latest version of APISIX?

@dickens7
Copy link
Contributor

Which version of APISIX are you using? Can reproduce it on the latest version of APISIX?

I am using apisix 2.13.2, 2.13.* can be reproduced

Version 2.14.* Not tested yet

@tzssangglass tzssangglass added the bug Something isn't working label Jul 25, 2022
@tzssangglass tzssangglass self-assigned this Jul 25, 2022
@tzssangglass
Copy link
Member

tzssangglass commented Jul 25, 2022

I am using apisix 2.13.2, 2.13.* can be reproduced

Version 2.14.* Not tested yet

I confirmed this as a bug on the master branch, thanks for the report and research.

I will fix it soon.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants