Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Open
sixtool opened this issue Aug 20, 2019 · 3 comments

Comments

@sixtool
Copy link

sixtool commented Aug 20, 2019

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
Copy link
Author

sixtool commented Aug 20, 2019

@leafo please help me!!!

@leafo
Copy link
Owner

leafo commented Aug 20, 2019

does your app work without using that library?

what are you passing into the serve function?

@sixtool
Copy link
Author

sixtool commented Aug 21, 2019

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants