lapis icon indicating copy to clipboard operation
lapis copied to clipboard

lapis and lua-resty-balancer attempt to index local 'app_cls' (a userdata value)

Open sixtool opened this issue 4 years ago • 3 comments

lapis and resty.chash module error

The following is the run in the init_by_lua stage

 local resty_chash = require "resty.chash"
local chash_up = resty_chash:new(nodes)
package.loaded.my_chash_up = chash_up 

When I use it on the lapis controller local chash_up = package.loaded.my_chash_up

When running the request, the following error is reported.

2019/08/20 10:11:09 [error] 78194#78194: *2 lua entry thread aborted: runtime error: /usr/local/share/lua/5.1/lapis/init.lua:17: attempt to index local 'app_cls' (a userdata value) stack traceback: coroutine 0: /usr/local/share/lua/5.1/lapis/init.lua: in function 'serve'

sixtool avatar Aug 20 '19 03:08 sixtool

@leafo please help me!!!

sixtool avatar Aug 20 '19 11:08 sixtool

does your app work without using that library?

what are you passing into the serve function?

leafo avatar Aug 20 '19 18:08 leafo

I have ab test requirement

If when I have 10 different versions of the web to buy the page style I need to set a different weight ratio for each page.

I want to use the lua-resty-balancer module to configure the access ratio for different pages.

Each page has a different id, and each id has a different weight. When nginx receives a user request, it automatically assigns a page id proportionally.

The following code is executed by me in the init_by_lua phase

local _M = {}
_M.VERSION = '0.10'
local mt = { __index = _M }

 local resty_chash = require "resty.chash"
local resty_roundrobin = require "resty.roundrobin"
		
 ---page ID = weigth %
local page_list = {
	["1985"] = 5,
	["1986"] = 3,
	["1987"] = 2,
}
@leafo  

-- XX: we can do the following steps to keep consistency with nginx chash
local str_null = string.char(0)

local pages, nodes = {}, {}
for cid, weight in pairs(page_list) do
	-- XX: we can just use serv as id when we doesn't need keep consistency with nginx chash
	local id = string.gsub(cid, ":", str_null)
    pages[id] = cid
	nodes[id] = weight
end

 
local rr_up = resty_roundrobin:new(page_list)
package.loaded.my_rr_up = rr_up  


 
local chash_up = resty_chash:new(nodes)
package.loaded.my_chash_up = chash_up
package.loaded.my_cids = pages

II want to get the my_rr_up module in the controller layer

local chash_up = package.loaded.my_chash_up

When running the request, the following error is reported.

2019/08/20 10:11:09 [error] 78194#78194: *2 lua entry thread aborted: runtime error: /usr/local/share/lua/5.1/lapis/init.lua:17: attempt to index local 'app_cls' (a userdata value) stack traceback: coroutine 0: /usr/local/share/lua/5.1/lapis/init.lua: in function 'serve'

sixtool avatar Aug 21 '19 09:08 sixtool