hi agentzh,
以下为测试代码
server
{
listen 80;
server_name test;
location /
{
content_by_lua '
local key = string.rep ("x", 200000)
local ctx = {}
local m, err = ngx.re.match(key, ".", "soja", ctx)
while m do
ngx.print(m[0])
m, err = ngx.re.match(key, ".", "soja", ctx)
end
';
}
}
其中字符串长度 200000 时有时会出错,有时不会,加大到 300000 时基本完全会出错。
出错时的现象,nginx cpu占用100%,输出中止,类似
[root@test conf]# curl "
http://test/"
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
出错时pstack 查看出错进程
[root@test conf]# pstack 15060
#0 0x000000000041838a in ngx_chain_update_chains ()
#1 0x00000000004549a9 in ngx_http_chunked_body_filter ()
#2 0x00000000004593e1 in ngx_http_gzip_body_filter ()
#3 0x000000000045a213 in ngx_http_postpone_filter ()
#4 0x000000000045a820 in ngx_http_ssi_body_filter ()
#5 0x000000000045e935 in ngx_http_charset_body_filter ()
#6 0x000000000047cf36 in ngx_http_xss_body_filter ()
#7 0x0000000000498c37 in ngx_http_lua_capture_body_filter ()
#8 0x00000000004b5e6f in ngx_http_rds_csv_body_filter ()
#9 0x0000000000418911 in ngx_output_chain ()
#10 0x00000000004455f9 in ngx_http_copy_filter ()
#11 0x0000000000454b09 in ngx_http_range_body_filter ()
#12 0x00000000004383ea in ngx_http_output_filter ()
#13 0x000000000049458a in ngx_http_lua_output_filter ()
#14 0x0000000000494e87 in ngx_http_lua_send_chain_link ()
#15 0x000000000048ae14 in ngx_http_lua_ngx_echo ()
#16 0x000000000048aeb1 in ngx_http_lua_ngx_print ()
#17 0x00002af4b00a1d3b in lj_BC_FUNCC () from /usr/local/openresty/luajit/lib/libluajit-5.1.so.2
#18 0x0000000000494f36 in ngx_http_lua_run_thread ()
#19 0x00000000004978aa in ngx_http_lua_content_by_chunk ()
#20 0x00000000004979c1 in ngx_http_lua_content_handler_inline ()
#21 0x00000000004975a7 in ngx_http_lua_content_handler ()
#22 0x000000000043cc21 in ngx_http_core_content_phase ()
#23 0x0000000000438063 in ngx_http_core_run_phases ()
#24 0x0000000000438160 in ngx_http_handler ()
#25 0x000000000044196d in ngx_http_process_request ()
#26 0x00000000004421aa in ngx_http_process_request_headers ()
#27 0x00000000004426c2 in ngx_http_process_request_line ()
#28 0x000000000043fd40 in ngx_http_init_request ()
#29 0x000000000042abaa in ngx_event_process_posted ()
#30 0x000000000042aa6f in ngx_process_events_and_timers ()
#31 0x00000000004307a8 in ngx_worker_process_cycle ()
#32 0x000000000042f107 in ngx_spawn_process ()
#33 0x000000000042fe8e in ngx_start_worker_processes ()
#34 0x0000000000431333 in ngx_master_process_cycle ()
#35 0x0000000000415d9d in main ()
换用 gmatch 现象类似。
configure arguments: --prefix=/usr/local/openresty/nginx --add-module=../ngx_devel_kit-0.2.18 --add-module=../echo-nginx-module-0.44 --add-module=../xss-nginx-module-0.03rc9 --add-module=../ngx_coolkit-0.2rc1 --add-module=../set-misc-nginx-module-0.22rc8 --add-module=../form-input-nginx-module-0.07 --add-module=../encrypted-session-nginx-module-0.02 --add-module=../srcache-nginx-module-0.19 --add-module=../ngx_lua-0.7.18 --add-module=../headers-more-nginx-module-0.19 --add-module=../array-var-nginx-module-0.03rc1 --add-module=../memc-nginx-module-0.13rc3 --add-module=../redis2-nginx-module-0.10 --add-module=../redis-nginx-module-0.3.6 --add-module=../auth-request-nginx-module-0.2 --add-module=../rds-json-nginx-module-0.12rc10 --add-module=../rds-csv-nginx-module-0.05rc2 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-http_ssl_module