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

ERR: attempt to index global '_debug' (a nil value) #57

Open
linsir opened this issue Sep 4, 2018 · 20 comments
Open

ERR: attempt to index global '_debug' (a nil value) #57

linsir opened this issue Sep 4, 2018 · 20 comments
Labels

Comments

@linsir
Copy link

linsir commented Sep 4, 2018

Hello, thank you share this project.and I try to run it with docker , but I does't work. this is the error.log.

2018/09/04 08:48:44 [error] 21#21: *1 lua entry thread aborted: runtime error: /usr/share/lua/5.1/std/normalize/_strict.lua:33: attempt to index global '_debug' (a nil value)
web_1   | stack traceback:
web_1   | coroutine 0:
web_1   | 	[C]: in function 'require'
web_1   | 	/usr/share/lua/5.1/lapis/init.lua:15: in function 'serve'
web_1   | 	content_by_lua(nginx.conf.compiled:28):1: in function <content_by_lua(nginx.conf.compiled:28):1>, client: 172.24.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:1001"

any idear?

@karai17
Copy link
Owner

karai17 commented Sep 4, 2018

Interesting. I'll have a look into it.

@karai17 karai17 added the bug label Sep 4, 2018
@linsir
Copy link
Author

linsir commented Sep 7, 2018

It seems like a problem of luaposix
and look at the std/normalize/_strict.lua

local setfenv = rawget(_G, 'setfenv') or function() end
local _ENV = {
   _debug = require 'std._debug',
   pcall = pcall,
   require = require,
   setmetatable = setmetatable,
}
setfenv(1, _ENV)
print(_debug)

the _debug is nil, the setfenv not works.

@karai17
Copy link
Owner

karai17 commented Sep 7, 2018

I am confused by this because nowhere in my code does _debug exist. Unless luaposix has a typo in their code somewhere..

posix is used in lapchan specifically for posix.crypt for generating tripcodes.

@linsir
Copy link
Author

linsir commented Sep 7, 2018

Thanks, I got it.

@linsir linsir closed this as completed Sep 7, 2018
@karai17 karai17 reopened this Sep 7, 2018
@karai17
Copy link
Owner

karai17 commented Sep 8, 2018

@linsir can you try updating luaposix? it was patched to fix this issue.

luaposix/luaposix#312

@linsir
Copy link
Author

linsir commented Sep 10, 2018

yes, I have updated the luaposix ,but get this error.

*2 lua entry thread aborted: runtime error: /usr/share/lua/5.1/posix/deprecated.lua:696: attempt to call global 'argscheck' (a nil value)

@gvvaughan
Copy link

Hi,

I cannot reproduce this error. posix._base has:

local HAVE_TYPECHECK, typecheck = pcall(require, 'typecheck')

return {
   argscheck = HAVE_TYPECHECK and typecheck.argscheck or function(_, fn)
      return fn
   end,
}

and then posix.deprecated has:

local _ENV = require 'posix._strict' {
   argscheck = require 'posix._base'.argscheck,
}

Where posix._strict returns:

return function(env, level)
   env = strict(env)
   setfenv(1+(level or 1), env)
   return env
end

What version of Lua are you using? Can you reproduce by installing luaposix with luarocks, and a require statement in the REPL? Does it fail with or without std.strict and/or std._debug installed?

@karai17
Copy link
Owner

karai17 commented Sep 13, 2018

lapchan runs in a Docker image using luajit and luarocks. I don't believe luastd is installed unless it is a dependency of luaposix.

@gvvaughan
Copy link

gvvaughan commented Sep 13, 2018

if you mean the optional std.strict and std._debug modules, they too are pcall required by luaposix like typecheck above. Nonetheless, I cant reproduce the typecheck error with or without those modules on luajit or puc-rio 5.1, 5.2 or 5.3... and the argscheck setting code above looks correct to me by inspection. If one of you you could send me the details I asked for above and a reproducer please, I'll have a better chance of understanding the failure condition and fixing it. (I'm holding off on a planned luaposix release to make sure it doesnt have this bug btw)

@karai17
Copy link
Owner

karai17 commented Sep 17, 2018

I don't have the time atm to test this personally so feel free to push your release and if this problem can be tracked down we can work on it at a later date.

@byoungdale
Copy link

byoungdale commented Apr 5, 2019

@gvvaughan I got this same error when I explicitly installed std.strict and std._debug via Luarocks and when not installed. Also, to note, I got this same error when installing the latest luaposix with luarocks install http://raw.github.com/luaposix/luaposix/master/luaposix-git-1.rockspec.

Here is the error:
2019/04/05 19:58:32 [error] 20#20: *1 lua entry thread aborted: runtime error: /usr/share/lua/5.1/posix/deprecated.lua:696: attempt to call global 'argscheck' (a nil value)

@gvvaughan
Copy link

@byoungdale thanks for the info - do you have a short piece of code that triggers the error with the luarocks you describe installing in place?

@byoungdale
Copy link

byoungdale commented Apr 6, 2019

Here is the full stack traceback when the error occurs:

web_1   | 2019/04/06 02:06:29 [error] 19#19: *1 lua entry thread aborted: runtime error: /usr/share/lua/5.1/posix/deprecated.lua:696: attempt to call global 'argscheck' (a nil value)
web_1   | stack traceback:
web_1   | coroutine 0:
web_1   | 	[C]: in function 'require'
web_1   | 	/usr/share/lua/5.1/lapis/init.lua:15: in function 'serve'
web_1   | 	content_by_lua(nginx.conf.compiled:28):1: in function <content_by_lua(nginx.conf.compiled:28):1>, client: 172.19.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1:1001"

That is all that I am getting. Does that help you at all? I will try to track down what is exactly triggering the error. But, it looks like it's something is lapis or openresty perhaps?

@gvvaughan
Copy link

Thanks, but no new clues in the stack trace :(

Maybe instrumenting posix._base to log what it is returning will help narrow it down, now that you have a reproducer? Here is what I put together that seems to work for me in all combinations of lua with or without all sensible combinations of std.strict and std._debug and typecheck:

local _open, _concat, _str = io.open, table.concat, require 'std.normalize'.str --tostring                                                                                           
local require = require                                                                                                                                                              
                                                                                                                                                                                     
do                                                                                                                                                                                   
   local f = _open('/tmp/posix.log', 'w+')                                                                                                                                           
   f:write('\n')                                                                                                                                                                     
   f:close()                                                                                                                                                                         
end                                                                                                                                                                                  
                                                                                                                                                                                     
local function log(prefix, ...)                                                                                                                                                      
   local parms, f = {...}, _open('/tmp/posix.log', 'a+')                                                                                                                             
   f:write(prefix)                                                                                                                                                                   
   for i = 1, #parms do                                                                                                                                                              
      f:write(_concat{' "', _str(parms[i]), '",'})                                                                                                                                   
   end                                                                                                                                                                               
   f:write('\n')                                                                                                                                                                     
   f:close()                                                                                                                                                                         
   return ...                                                                                                                                                                        
end                                                                                                                                                                                  
                                                                                                                                                                                     
                                                                                                                                                                                     
package.preload['posix._strict'] = function()                                                                                                                                        
   local setfenv = rawget(_G, 'setfenv') or function() end                                                                                                                           
                                                                                                                                                                                     
   local strict                                                                                                                                                                      
   do                                                                                                                                                                                
      local ok, _debug = log('posix._strict: ok, debug =', pcall(require, 'std._debug.init'))                                                                                        
      if ok and _debug.strict then                                                                                                                                                   
         ok, strict = pcall(require, 'std.strict.init')                                                                                                                              
      end                                                                                                                                                                            
      if not ok then                                                                                                                                                                 
         strict = function(env)                                                                                                                                                      
            return env                                                                                                                                                               
         end                                                                                                                                                                         
      end                                                                                                                                                                            
   end                                                                                                                                                                               
                                                                                                                                                                                     
   return log('posix._strict: return ', function(env, level)                                                                                                                         
      env = log('posix._strict: env =', strict(env))                                                                                                                                 
      setfenv(1+(level or 1), env)                                                                                                                                                   
      return env                                                                                                                                                                     
   end)                                  
end                                                                                                                                                                                  
                                                                                                                                                                                     
                                                                                                                                                                                     
package.preload['posix._base'] = function()                                                                                                                                          
   local HAVE_TYPECHECK, typecheck = log('posix._base: HAVE_TYPECHECK, typecheck =', pcall(require, 'typecheck'))                                                                    
                                                                                                                                                                                     
   return {                                                                                                                                                                          
      argscheck = log('posix._base: argscheck =', HAVE_TYPECHECK and typecheck.argscheck or function(_, fn)                                                                          
         return fn                                                                                                                                                                   
      end),                                                                                                                                                                          
   }                                                                                                                                                                                 
end                                                                                                                                                                                  
                                                                                                                                                                                     
-- posix.deprecated                                                                                                                                                                  
                                                                                                                                                                                     
local _ENV = log('_ENV =', require 'posix._strict' {                                                                                                                                 
   argscheck = log('posix.deprecated: argscheck =', require 'posix._base'.argscheck),                                                                                                
})                                                                                                                                                                                   
                                                                                                                                                                                     
log('_ENV.argscheck = ', _ENV.argscheck)                    

If you don't have std.normalize installed, you can use just tostring instead of std.normalize.str, but then you'll just see table: 0xnnnnnn instead of the contents of a table in the log file...

Does the code above work for you? If not, what shows in /tmp/posix.log after provoking a failure?

@byoungdale
Copy link

So, I replaced posix/_base.lua with your code above, and I get the original error:

web_1   | 2019/04/07 20:55:07 [error] 20#20: *2 lua entry thread aborted: runtime error: /usr/share/lua/5.1/std/normalize/_strict.lua:33: attempt to index global '_debug' (a nil value)
web_1   | stack traceback:
web_1   | coroutine 0:
web_1   | 	[C]: in function 'require'
web_1   | 	/usr/share/lua/5.1/lapis/init.lua:15: in function 'serve'
web_1   | 	content_by_lua(nginx.conf.compiled:28):1: in function <content_by_lua(nginx.conf.compiled:28):1>, client: 172.19.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1:1001"

And nothing is being to the log.

@gvvaughan
Copy link

gvvaughan commented Apr 7, 2019

Oh I wasn't clear enough there, sorry. That wasn't meant to be a direct replacement for posix/_base.lua, but rather a standalone reproducer instrumenting the various call stack elements that seem to be involved in the crash.

If you are able to run that file inside your lapis environment, and the crash still reproduces it will produce a log file that will help me understand what is going wrong. Alternatively, if you'd prefer (or if it's not possible to run that file from lapis), you could use just the log function to wrap calls to the installed posix/deprecated.lua:_ENV.argscheck, posix/_base.lua:argscheck, and posix/_strict.lua return function (by adding it to the posix/_base.lua return table, and wrapping the relevant parts of the code).

If it's not straight forward to hand-roll that, please let me know, and I'll make separate branch in the luaposix repo with the equivalent logging turned on.

@byoungdale
Copy link

Hi @gvvaughan, I tried to use the log function in various places, but I just kept getting the same *2 lua entry thread aborted: runtime error: /usr/share/lua/5.1/std/normalize/_strict.lua:33: attempt to index global '_debug' (a nil value) error every time. I can't tell if it's something I am doing wrong or not. I made sure all the libraries are installed and tried to use the logging in a few spots. If you are willing to make a separate branch with more logging, I will run it.

@gvvaughan
Copy link

awesome, thanks for sticking with it. It’ll take me a few days to make the time, but I’ll let you know...

@byoungdale
Copy link

byoungdale commented Apr 19, 2019

Just as an FYI to anyone else, I changed these luarocks modules to older versions and was able to get my docker instance of lapis-chan running.

RUN luarocks install std.normalize 2.0.1-1
RUN luarocks install luaposix 34.0.3-1

Here is the whole Luarocks install section of my Dockerfile that got everything running again:

# Install from LuaRocks
RUN luarocks install luasec
RUN luarocks install bcrypt
RUN luarocks install giflib --server=http://luarocks.org/dev
RUN luarocks install i18n
RUN luarocks install lapis
RUN luarocks install luafilesystem
RUN luarocks install std.strict
RUN luarocks install std._debug 1.0-1
RUN luarocks install std.normalize 2.0.1-1
RUN luarocks install luaposix 34.0.3-1
RUN luarocks install magick
RUN luarocks install markdown
RUN luarocks install md5

Everything else in the Dockerfile is the same.

@karai17
Copy link
Owner

karai17 commented May 22, 2019

@gvvaughan Any update on this issue? Is there a change I should make to Lapis-chan to help it work better with the latest version of luaposix, or is there perhaps a bug in luaposix that is causing this issue?

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

No branches or pull requests

4 participants