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

[alert] ****: worker process **** exited on signal 11 when require zlib on Mac #59

Open
shiziwen opened this issue Apr 7, 2022 · 9 comments

Comments

@shiziwen
Copy link

shiziwen commented Apr 7, 2022

nginx.conf:

location /test {
          echo "hello, world!";
          content_by_lua '
            local zlib = require "zlib"
            ngx.log(ngx.DEBUG, "test-------")
            local stream = zlib.deflate()("123456","finish")
            ngx.say(stream)
          ';
        }

How can I install Lua-zlib:

  1. update INCDIR to "?= -I/usr/local/include/lua5.4" in Makefile
  2. make macosx
  3. cp zlib.so /usr/local/openresty/lualib/

when I send a request to 127.0.0.1/test, I got the following logs:

2022/04/07 18:10:21 [notice] 78887#0: signal 20 (SIGCHLD) received from 78901
2022/04/07 18:10:21 [alert] 78887#0: worker process 78901 exited on signal 11
2022/04/07 18:10:21 [notice] 78887#0: start worker process 78922
2022/04/07 18:10:21 [notice] 78887#0: signal 23 (SIGIO) received
@shiziwen
Copy link
Author

shiziwen commented Apr 7, 2022

I have add some debug log and I found that when require zlib, the worker process got signal and exits.

@shiziwen
Copy link
Author

shiziwen commented Apr 7, 2022

I have tried to test the Lua command, it works well.

$ echo abcdefg > aaa
$ gzip aaa
$lua
Lua 5.4.2  Copyright (C) 1994-2020 Lua.org, PUC-Rio
> f = io.open("aaa.gz", "r")
> data = f:read()
> data
 ؓNbaaaKLJNIMK�$*S
> zlib = require "zlib"
> zlib.inflate()(data)
abcdefg
	true	32	8
>

@shiziwen
Copy link
Author

shiziwen commented Apr 7, 2022

I have tried to install by luarocks.

I download the lua-zlib-1.2-1.rockspec from https://github.com/brimworks/lua-zlib/blob/master/rockspecs/lua-zlib-1.2-1.rockspec, and update url to "git+https://github.com/brimworks/lua-zlib.git".

$luarocks install lua-zlib-1.2-1.rockspec  ZLIB_DIR=/usr/local/Cellar/zlib/1.2.11/
cp /usr/local/lib/lua/5.4/zlib.so /usr/local/openresty/lualib/

then when I send request ,I got the following errors:

2022/04/07 18:57:18 [error] 90565#0: *8 lua entry thread aborted: runtime error: error loading module 'zlib' from file '/usr/local/openresty/lualib/zlib.so':
	dlopen(/usr/local/openresty/lualib/zlib.so, 6): Symbol not found: _luaL_checkversion_
  Referenced from: /usr/local/openresty/lualib/zlib.so
  Expected in: dynamic lookup

stack traceback:
coroutine 0:
	[C]: in function 'require'
	content_by_lua(nginx.conf:87):2: in main chunk, client: 127.0.0.1, server: 127.0.0.1, request: "GET /test HTTP/1.1", host: "127.0.0.1:8080"

@shiziwen
Copy link
Author

shiziwen commented Apr 7, 2022

I have solved the problem.

$ git diff
diff --git a/Makefile b/Makefile
index 801ea04..191744d 100644
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,8 @@
 # Inform the location to intall the modules
 LUAPATH  ?= /usr/share/lua/5.1
 LUACPATH ?= /usr/lib/lua/5.1
-INCDIR   ?= -I/usr/include/lua5.1
-LIBDIR   ?= -L/usr/lib
+INCDIR   ?= -I/usr/local/openresty/luajit/include/luajit-2.1
+LIBDIR   ?= -L/usr/local/openresty/luajit/lib

 # For Mac OS X: set the system version
 MACOSX_VERSION = 10.4
@@ -11,7 +11,7 @@ MACOSX_VERSION = 10.4
 CMOD = zlib.so
 OBJS = lua_zlib.o

-LIBS = -lz -llua -lm
+LIBS = -lz -lluajit-5.1 -lm
 WARN = -Wall -pedantic

 BSD_CFLAGS  = -O2 -fPIC $(WARN) $(INCDIR) $(DEFS)

and then, it works.

@alerque
Copy link
Contributor

alerque commented Apr 7, 2022

Did you try using the --lua-dir flag on luarocks when you installed this? If you are using a non-default Lua installation as is indicated above you need to specify where the headers are when you compile stuff for it...

@shiziwen
Copy link
Author

shiziwen commented Apr 8, 2022

@alerque Actually, I didn't use --lua-dir flag on luarocks.

If I want to use --lua-dir flag, what the value should be?

$ which lua
/usr/local/bin/lua

like this?

@shiziwen
Copy link
Author

shiziwen commented Apr 8, 2022

@alerque
Another question, after I modified the Makefile like above which specified to use luajit, the maked zlib.so works well.

So, why should I use luajit instead of lua?

@alerque
Copy link
Contributor

alerque commented Apr 8, 2022

When you run luarocks normally it uses your system's default Lua installation. This affects two major things: the installation location and what header files any C modules get compiled against. If you are installing in some vendored location for a project the first might not be an issue, but the second is even more likely to be a problem. Each version of Lua has different headers and modules (particularly C based ones like this one!) must be built against the Lua headers for the version they will run with.

I think you could have just used the --lua-version and --lua-dir arguments to specify you wanted to build against your (luajit derived) openresty Lua interpreter instead of your system default and then not mess with the Makefile at all. What you did to the Makefile accomplished roughly the same thing, just in a round about way.

@shiziwen
Copy link
Author

shiziwen commented Apr 8, 2022

@alerque Thanks for your reply, I will try to use luarocks with the --lua-version and --lua-dir arguments.

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