wrk icon indicating copy to clipboard operation
wrk copied to clipboard

PANIC: unprotected error in call to Lua API (attempt to index a nil value)

Open centminmod opened this issue 8 years ago • 11 comments

I install Wrk via git clone on CentOS 7.4 64bit systems. Usually it works fine except for one system I get the following error when running wrk with parameters

PANIC: unprotected error in call to Lua API (attempt to index a nil value)
wrk -v
wrk 4.0.2-2-g91655b5 [epoll] Copyright (C) 2012 Will Glozer
Usage: wrk <options> <url>                            
  Options:                                            
    -c, --connections <N>  Connections to keep open   
    -d, --duration    <T>  Duration of test           
    -t, --threads     <N>  Number of threads to use   
                                                      
    -s, --script      <S>  Load Lua script file       
    -H, --header      <H>  Add header to request      
        --latency          Print latency statistics   
        --timeout     <T>  Socket/request timeout     
    -v, --version          Print version details      
                                                      
  Numeric arguments may include a SI unit (1k, 1M, 1G)
  Time arguments may include a time unit (2s, 2m, 2h)
 ldd wrk
        linux-vdso.so.1 =>  (0x00007ffd9215e000)
        libluajit-5.1.so.2 => /opt/wrk-luajit/lib/libluajit-5.1.so.2 (0x00007f774201a000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f7741ded000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f7741aeb000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f77418e7000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f7741523000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f774130d000)
        /lib64/ld-linux-x86-64.so.2 (0x000055f9372b6000)
/opt/wrk-openssl/bin/openssl version -a
OpenSSL 1.1.0f  25 May 2017
built on: reproducible build, date unspecified
platform: linux-x86_64
compiler: ccache gcc -DZLIB -DZLIB_SHARED -DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_DYNAMIC_ENGINE -DOPENSSL_PIC -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DRC4_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DPADLOCK_ASM -DPOLY1305_ASM -DOPENSSLDIR="\"/opt/wrk-openssl\"" -DENGINESDIR="\"/opt/wrk-openssl/lib/engines-1.1\""  -Wa,--noexecstack
OPENSSLDIR: "/opt/wrk-openssl"
ENGINESDIR: "/opt/wrk-openssl/lib/engines-1.1"

I installed using following steps on all systems that are working as well

OPENSSL_VERSION='1.1.0f'
rm -rf /svr-setup/wrk-openssl
mkdir -p /svr-setup/wrk-openssl
cd /svr-setup/wrk-openssl
wget -cnv https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
tar xvzf openssl-${OPENSSL_VERSION}.tar.gz
cd openssl-${OPENSSL_VERSION}
OPENSSL_CUSTOMPATH='/opt/wrk-openssl'
export STATICLIBSSL="${OPENSSL_CUSTOMPATH}"
LIBRPATH='/opt/wrk-openssl/lib'
./config -Wl,--enable-new-dtags,-rpath,'$(LIBRPATH)' --prefix=$STATICLIBSSL --openssldir=$STATICLIBSSL no-shared zlib-dynamic
make -j2
make install_ssldirs
make install_sw
\cp -Rpf /etc/ssl/certs/* /opt/wrk-openssl/certs/

cd /svr-setup
rm -rf /svr-setup/wrk-luajit
git clone http://luajit.org/git/luajit-2.0.git wrk-luajit
cd wrk-luajit
make -j2 PREFIX=/opt/wrk-luajit
make install PREFIX=/opt/wrk-luajit
MAJVER=$(awk -F "=  " '/MAJVER=  / {print $2}' Makefile)
MINVER=$(awk -F "=  " '/MINVER=  / {print $2}' Makefile)
RELVER=$(awk -F "=  " '/RELVER=  / {print $2}' Makefile)
PREREL=$(awk -F "=  " '/PREREL=  / {print $2}' Makefile)
rm -rf /opt/wrk-luajit/bin/luajit
ln -sf /opt/wrk-luajit/bin/luajit-${MAJVER}.${MINVER}.${RELVER}${PREREL} /opt/wrk-luajit/bin/luajit

cd /svr-setup
rm -rf /svr-setup/wrk
git clone https://github.com/wg/wrk
cd wrk
export PATH=$PATH:/opt/wrk-luajit/bin
export LDFLAGS='-Wl,-rpath,/opt/wrk-luajit/lib'
make WITH_LUAJIT=/opt/wrk-luajit WITH_OPENSSL=/opt/wrk-openssl
\cp -af wrk /usr/local/bin/wrk

centminmod avatar Sep 25 '17 04:09 centminmod

I'm getting this error using wrk package from Ubuntu 18.04 which is also 4.0.2-2 version, did you manage to make it work?

dantti avatar May 09 '18 15:05 dantti

i just use make these days works on my forked wrk branch

centminmod avatar Jun 08 '18 17:06 centminmod

Experiencing this with Mint 19

Xplouder avatar Oct 07 '18 16:10 Xplouder

I'm getting this error using wrk package from Ubuntu 18.04 which is also 4.0.2-2 version, did you manage to make it work?

me too

giovibal avatar Jan 03 '19 15:01 giovibal

i occurs the runtime error,but i solved

  1. ensure the compile-make luajit is same with the ldd dependency luajit
  2. it occurs when the system LD_LIBRARY_PATH has a luajit,this luajit is not same with the compile luajit

landon30 avatar May 06 '19 13:05 landon30

Same issue on Debian 9:

Package: wrk                             
Version: 4.0.2-2~deb9u1
State: installed
Automatically installed: no
Priority: optional
Section: web
Maintainer: Robert Edmonds <[email protected]>
Architecture: amd64
Uncompressed Size: 116 k
Depends: libc6 (>= 2.14), libluajit-5.1-2, libssl1.1 (>= 1.1.0)
Description: HTTP benchmarking tool
 wrk is a modern HTTP benchmarking tool capable of generating significant load when run on a single multi-core CPU. It combines a multithreaded design
 with scalable event notification systems such as epoll and kqueue. 
 
 An optional LuaJIT script can perform HTTP request generation, response processing, and custom reporting.
Homepage: https://github.com/wg/wrk

ldd:

ldd /usr/bin/wrk
        linux-vdso.so.1 (0x00007fff71b94000)
        libluajit-5.1.so.2 => /usr/lib/x86_64-linux-gnu/libluajit-5.1.so.2 (0x00007f1b1ca8b000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f1b1c86e000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f1b1c56a000)
        libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f1b1c0d0000)
        libssl.so.1.1 => /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007f1b1be64000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1b1bac5000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f1b1b8c1000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f1b1b6aa000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f1b1cf18000)

luajit:

aptitude show libluajit-5.1-2
Package: libluajit-5.1-2                 
Version: 2.1.0~beta3+dfsg-5.1~bpo9+1
State: installed
Automatically installed: no
Multi-Arch: same
Priority: optional
Section: interpreters
Maintainer: Enrico Tassi <[email protected]>
Architecture: amd64
Uncompressed Size: 528 k
Depends: libluajit-5.1-common (= 2.1.0~beta3+dfsg-5.1~bpo9+1), libc6 (>= 2.14), libgcc1 (>= 1:3.3)

On Debian 9, the default libluajit-5.1-2 version is 2.0.4+dfsg-1+b1. If you're running on backports luajit (2.1.0~beta3+dfsg-5.1~bpo9+1), you need to recompile wrk.

deric avatar Nov 28 '19 09:11 deric

I'm getting the same on macos with clang-12 after stripping the binary:

$ file wrk
wrk: Mach-O 64-bit executable x86_64
$ otool -L wrk
wrk:
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.60.1)
	/opt/pkg/lib/libssl.1.1.dylib (compatibility version 1.1.0, current version 1.1.0)
	/opt/pkg/lib/libcrypto.1.1.dylib (compatibility version 1.1.0, current version 1.1.0)
$ ./wrk -c 1 -t 1 http://localhost
unable to connect to localhost:http Connection refused
$ strip wrk
$ ./wrk -c 1 -t 1 http://localhost
PANIC: unprotected error in call to Lua API (attempt to index a nil value)

Have no idea what's the real reason. I'm building wrk with static LuaJIT, and I don't have any LuaJIT libs in the system.

UDPATE: it is failing in https://github.com/wg/wrk/blob/master/src/script.c#L102:

$ nm wrk.orig | fgrep luaJIT_BC
0000000100080460 S _luaJIT_BC_wrk
$ nm wrk.stripped | fgrep luaJIT_BC
$ 

Looks interesting.

defanator avatar Apr 07 '21 15:04 defanator

i occurs the runtime error,but i solved

  1. ensure the compile-make luajit is same with the ldd dependency luajit
  2. it occurs when the system LD_LIBRARY_PATH has a luajit,this luajit is not same with the compile luajit

this do solve my problem!

niT-Tin avatar Aug 21 '21 03:08 niT-Tin

Still happening in Ubuntu 23.10 :(

KangoV avatar Oct 28 '23 21:10 KangoV

@centminmod Thanks your fork is working on WSL https://github.com/centminmod/wrk/tree/centminmod

I've been receiving some messages, I don't know if this is normal

unable to record connect unable to record connect unable to record first byte metrics unable to record first byte metrics

insinfo avatar Nov 06 '23 19:11 insinfo

Same problem here with this script.

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 23.04
Release:        23.04
Codename:       lunar

josecelano avatar Mar 14 '24 16:03 josecelano