Kong / openresty-patches

Moved to https://github.com/Kong/kong-build-tools
Apache License 2.0
14 stars 6 forks source link

After source compilation on centos7 and macOS: Segmentation Fault #41

Open leopeng1995 opened 5 years ago

leopeng1995 commented 5 years ago

I want to hack Kong 1.1.2 source codes, however I stuck in segmentation fault after source compilation.

[vagrant@localhost openresty-1.13.6.2]$ uname -a
Linux localhost.localdomain 3.10.0-957.12.2.el7.x86_64 #1 SMP Tue May 14 21:24:32 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
# Compile OpenSSL 1.1.1b separately
https://www.openssl.org/source/openssl-1.1.1b.tar.gz
tar -xzvf openssl-1.1.1b.tar.gz
./config \
    --prefix=/tmp/openssl-1.1.1b \
    --openssldir=/tmp/openssl-1.1.1b \
    no-unit-test
wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
tar -xzvf openresty-1.13.6.2.tar.gz
git clone https://github.com/Kong/openresty-patches.git
cd openresty-1.13.6.2/bundle/
for i in ../../openresty-patches/patches/1.13.6.2/*.patch; do patch -p1 < $i; done
cd ..
./configure \
  --with-cc-opt='-I/tmp/openssl-1.1.1b/include' \
  --with-ld-opt='-L/tmp/openssl-1.1.1b/lib -Wl,-rpath,/tmp/openssl-1.1.1b/lib' \
  --with-pcre-jit \
  --with-http_ssl_module \
  --with-http_realip_module \
  --with-http_stub_status_module \
  --with-http_v2_module \
  --with-stream_ssl_preread_module \
  --with-stream_realip_module \
  --with-luajit-xcflags="-DLUAJIT_NUMMODE=2" \
  -j4
make -j4
sudo make install

Or compile OpenSSL 1.1.1b together with OpenResty 1.13.6.2:

./configure \
  --with-openssl=../openssl-1.1.1b \
  --with-openssl-opt="-g shared -DPURIFY no-unit-test --prefix=/tmp/openssl-1.1.1b --openssldir=/tmp/openssl-1.1.1b" \
  --with-pcre=../pcre-8.41 \
  --with-pcre-jit \
  --with-http_ssl_module \
  --with-http_realip_module \
  --with-http_stub_status_module \
  --with-http_v2_module \
  --with-stream_ssl_preread_module \
  --with-stream_realip_module \
  --with-luajit-xcflags="-DLUAJIT_NUMMODE=2" \
  -j4
make -j4
sudo make install

After source compilation, I ran this command and got segmentation fault. Because of that, I cannot run tests.

/usr/local/openresty/nginx/sbin/nginx -p servroot/  -c nginx.conf

However, if I do not apply openresty-patches, I won't get segmentation fault. But I got warning message about missing patches.

[vagrant@localhost kong-mysql]$ /usr/local/openresty/nginx/sbin/nginx -p servroot/  -c nginx.conf
nginx: [warn] [lua] getssl.lua:10: OpenResty patch missing. See https://github.com/Kong/openresty-patches
nginx: [warn] [lua] init.lua:326: init(): missing "ngx.balancer".set_ssl_ctx API. Dynamic client SSL_CTX* will be unavailable
[vagrant@localhost kong-mysql]$ /usr/local/openresty/nginx/sbin/nginx -V
nginx version: openresty/1.13.6.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.1.1b  26 Feb 2019
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -I/tmp/openssl-1.1.1b/include' --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.61 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.13 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.5 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/tmp/openssl-1.1.1b/lib -Wl,-rpath,/tmp/openssl-1.1.1b/lib' --with-pcre-jit --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module --with-http_v2_module --with-stream_ssl_preread_module --with-stream_realip_module --with-stream --with-stream_ssl_module
leopeng1995 commented 5 years ago

I also see these issues https://github.com/Kong/kong/issues/4471 and https://github.com/Kong/openresty-patches/pull/39 on MacOS. I tried to compile openresty the same way on MacOS and got segmentation fault 11 similarly. It seems like pcre 8.43 bug. So I downgrade system pcre version to 8.41 and got the same error. I also tried to compile pcre in compilation option and failed.

./configure \
  --with-cc-opt='-I/tmp/openssl-1.1.1b/include' \
  --with-ld-opt='-L/tmp/openssl-1.1.1b/lib -Wl,-rpath,/tmp/openssl-1.1.1b/lib' \
  --with-pcre=../pcre-8.41 \
  --with-pcre-jit \
  --with-http_ssl_module \
  --with-http_realip_module \
  --with-http_stub_status_module \
  --with-http_v2_module \
  --with-stream_ssl_preread_module \
  --with-stream_realip_module \
  --with-luajit-xcflags="-DLUAJIT_NUMMODE=2" \
  -j4
pcre: stable 8.41 (bottled), HEAD
Perl compatible regular expressions library
http://www.pcre.org/
/usr/local/Cellar/pcre/8.41 (204 files, 5.4MB) *
  Built from source on 2019-06-14 at 14:46:49
leopeng1995 commented 5 years ago

So I hope the Kong official and community could help me. Thanks.