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

libresty_ffi.so: cannot open shared object file #4

Open
Bkndf opened this issue Nov 21, 2024 · 8 comments
Open

libresty_ffi.so: cannot open shared object file #4

Bkndf opened this issue Nov 21, 2024 · 8 comments

Comments

@Bkndf
Copy link

Bkndf commented Nov 21, 2024

My Dockerfile (I based it on the official image):

ARG RESTY_VERSION="1.27.1.1"
...
    && cd /tmp \
    && curl -fSL https://openresty.org/download/openresty-${RESTY_VERSION}.tar.gz -o openresty-${RESTY_VERSION}.tar.gz \
    && tar xzf openresty-${RESTY_VERSION}.tar.gz \
    && cd /tmp/openresty-${RESTY_VERSION} \
    && if [ -n "${RESTY_EVAL_POST_DOWNLOAD_PRE_CONFIGURE}" ]; then eval $(echo ${RESTY_EVAL_POST_DOWNLOAD_PRE_CONFIGURE}); fi \
    && eval ./configure -j${RESTY_J} ${_RESTY_CONFIG_DEPS} ${RESTY_CONFIG_OPTIONS} ${RESTY_CONFIG_OPTIONS_MORE} ${RESTY_LUAJIT_OPTIONS} ${RESTY_PCRE_OPTIONS} \
    && make -j${RESTY_J} \
    && make -j${RESTY_J} install \
    && cd /tmp \
    && curl -fSL https://luarocks.github.io/luarocks/releases/luarocks-${RESTY_LUAROCKS_VERSION}.tar.gz -o luarocks-${RESTY_LUAROCKS_VERSION}.tar.gz \
    && tar xzf luarocks-${RESTY_LUAROCKS_VERSION}.tar.gz \
    && cd luarocks-${RESTY_LUAROCKS_VERSION} \
    && ./configure \
        --prefix=/usr/local/openresty/luajit \
        --with-lua=/usr/local/openresty/luajit \
        --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1 \
    && make build \
    && make install

And I put the lua-resty-ffi installation into the build:

RUN apt-get update && apt-get install -y file build-essential libpcre2-dev libssl-dev
RUN export OR_SRC=/tmp/openresty-${RESTY_VERSION} \
    && /usr/local/openresty/luajit/bin/luarocks config variables.OR_SRC /tmp/openresty-${RESTY_VERSION} \
    && /usr/local/openresty/luajit/bin/luarocks install lua-resty-ffi

This successfully compiled, openresty started up.

But when I try to test it, I get an error:

2024/11/21 00:36:49 [error] 1324#1324: *3 lua entry thread aborted: runtime error: /usr/local/openresty/luajit/share/lua/5.1/resty_ffi.lua:101: libresty_ffi.so: cannot open shared object file: No such file or directory
stack traceback:
coroutine 0:
[C]: in function 'load'
/usr/local/openresty/luajit/share/lua/5.1/resty_ffi.lua:101: in function 'load_ffi'
/hello.lua:3: in main chunk, server: localhost, request: "GET /hello HTTP/1.1", host: "127.0.0.1:8080"


My lua code:

require("resty_ffi")

local demo = ngx.load_ffi("test.so")
location /hello {
            content_by_lua_file /hello.lua;
}

All the files are in place, I checked it that way:

luarocks show lua-resty-ffi

License:         BSD-3-Clause
Homepage:       https://github.com/kingluo/lua-resty-ffi
Installed in:   /usr/local/openresty/luajit

Modules:
        libresty_ffi (/usr/local/openresty/luajit/lib/lua/5.1/libresty_ffi.so)
        resty_ffi (/usr/local/openresty/luajit/share/lua/5.1/resty_ffi.lua)

I even tried just writing the path to libresty_ffi.so in resty_ffi.lua, but I got a crash error:

[alert] 1#1: worker process 1324394 exited on signal 6
 buffer overflow detected : terminated
 buffer overflow detected : terminated

local handle = ffi.load("/usr/local/openresty/luajit/lib/lua/5.1/libresty_ffi.so", true)

@kingluo
Copy link
Owner

kingluo commented Nov 21, 2024

It requires thread pool support from Nginx. Can you add "--with-threads" and retry?
Also, it is recommended to test it on a plain Ubuntu system before integrating it into the Dockerfile.

I haven't tried 1.27 yet, will try it later, please stay tuned.

@Bkndf
Copy link
Author

Bkndf commented Nov 21, 2024

Thanks for the reply!

Yes, I build initially with --with-threads flag https://github.com/openresty/docker-openresty/blob/78d64677f91e01912fe13e62473d1322844ac704/noble/Dockerfile#L73, similar functionality with ngx.run_worker_thread works.


I tried via build on Ubuntu 20.04.6 LTS, but it didn't work at the require(“resty_ffi”) point:

[error] 3689544#3689544: *1 lua entry thread aborted: runtime error: content_by_lua(nginx.conf:49):2: module 'resty_ffi' not found:
        no field package.preload['resty_ffi']

As tested:

  1. cd /opt
  2. git clone https://github.com/kingluo/lua-resty-ffi
  3. cd lua-resty-ffi
  4. ./build.sh
  5. cd lua-resty-ffi/examples/go/
  6. added it to nginx.conf:
location /hello {
    content_by_lua_block {
        require("resty_ffi")

        local demo = ngx.load_ffi("test.so")
    }
}
  1. make run
  2. curl http://127.0.0.1:20000/hello

@kingluo
Copy link
Owner

kingluo commented Nov 23, 2024

It should be caused by this fixed bug. I forgot to upload a new luarocks version. I will do it later.

@kingluo
Copy link
Owner

kingluo commented Nov 23, 2024

@Bkndf done, please retry the latest version on luarocks. Thanks for your bug report.

@Bkndf
Copy link
Author

Bkndf commented Nov 25, 2024

Yes, it works! Thank you very much!
I'll keep implementing and figuring it out. :)

@Bkndf Bkndf closed this as completed Nov 25, 2024
@Bkndf
Copy link
Author

Bkndf commented Dec 27, 2024

Hello, I apologize for reopening the issue.
It's just the same problem, but with the resty_ffi_python module.

*** buffer overflow detected ***: terminated
2024/12/27 11:02:12 [alert] 1#1: worker process 13 exited on signal 6

@Bkndf Bkndf reopened this Dec 27, 2024
@kingluo
Copy link
Owner

kingluo commented Dec 27, 2024

yes, I forgot to update the python rockspec. I'll do it later.

@kingluo
Copy link
Owner

kingluo commented Jan 1, 2025

@Bkndf done. Please check the main-2 version.

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