openresty / openresty/lua-nginx-module

resty http got BAD ARGUMENT exception by accident

Open
#2,178 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

This place is for bug reports and development discussions only. For general questions and
discussions, please join the openresty-en mailing list instead: https://openresty.org/en/community.html
ERROR Stacks:

2023/04/06 14:14:08 [error] 121939#121939: *28808 lua entry thread aborted: runtime error: /usr/local/apisix//deps/share/lua/5.1/resty/http.lua:365: bad argument #1 to 'str_sub' (string expected, got boolean)
stack traceback:
coroutine 0:
        [C]: in function 'str_sub'
        /usr/local/apisix//deps/share/lua/5.1/resty/http.lua:365: in function '_receive_status'
        /usr/local/apisix//deps/share/lua/5.1/resty/http.lua:777: in function 'request'
        /usr/local/apisix//deps/share/lua/5.1/resty/consul.lua:156: in function 'get'
        /usr/local/apisix/apisix/discovery/consul/init.lua:342: in function </usr/local/apisix/apisix/discovery/consul/init.lua:273>, context: ngx.timer

Here is the code snippet:

local function call_url1(url)
    local c = http.new()
    -- call the url
end

local function call_url2(url)
    local c = http.new()
    -- call the url
end

function _M.connect(premature)
    if premature then
        return
    end

   local url1_thread, url1_err = ngx.thread.spawn(call_url1, url1)
   if not url1_thread then
       log.error("spawn url1 thread error")
       return
   end
   local url2_thread, url2_err = ngx.thread.spawn(call_url2, url2)
   if not url2_thread then
       log.error("spawn url2 thread error")
       return
   end
   local thread_wait_ok, wait_res = ngx.thread.wait(url1_thread, url2_thread)
   ngx.thread.kill(url1_thread)
   ngx.thread.kill(url2_thread)
   if not thread_wait_ok then
        log.error("failed to wait thread: ", err, ", wait_res: ", wait_res)
        return
    end
    
    local c3 = http.new()
    -- call other url and got exception here
end

Ensure you have provided the following details while reporting a problem:

  • The exact version of the related software, including but not limited to the OpenResty version
    (if any), the NGINX core version, the ngx_lua module version,
nginx version: openresty/1.21.4.1

and your operating system version.

  • A minimal and standalone test case that others can easily run on their side and
    reproduce the issue you are seeing.
  • Do not simply say "something is broken" or "something does not work". Always provide
    as much details as possible. Always describe the symptoms and your expected results.
  • You can (temporarily) enable the nginx debugging logs to see the internal workings
    of NGINX in your nginx''s error.log file. See http://nginx.org/en/docs/debugging_log.html
    The same instructions apply equally well to OpenResty.
  • If you are seeing crashes, please provide the full backtrace for the crash. See
    https://www.nginx.com/resources/wiki/start/topics/tutorials/debugging/#core-dump
    for more details.

Please, do not use Chinese here. This place is considered English only. If you
really want to use Chinese, please join and post to the openresty (Chinese)
mailing list instead. Please see https://openresty.org/en/community.html Thanks for
your cooperation.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the stack trace at resty/http.lua:365 and the coroutine pattern in the report, then inspect the related calls in resty/consul.lua:156 and apisix/discovery/consul/init.lua:342. Reproduce the BAD ARGUMENT exception with a minimal standalone case; completion requires a confirmed cause and a regression check, but the report does not define one.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.