ledgetech / lua-resty-http

Lua HTTP client cosocket driver for OpenResty / ngx_lua.
BSD 2-Clause "Simplified" License
2.01k stars 623 forks source link

resty http got BAD ARGUMENT exception by accident #294

Open Fabriceli opened 1 year ago

Fabriceli commented 1 year ago

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)
    -- long pull
    -- Blocking request, increase timeout
    -- https://www.consul.io/api/index.html#blocking-queries
    local c = http.new()
    -- call the url
end

local function call_url2(url)
    -- long pull
    -- Blocking request, increase timeout
    -- https://www.consul.io/api/index.html#blocking-queries
    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
    -- short pull
end

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

jzhao20230918 commented 5 months ago

hello, got same issue, any updates?