Bug 62726 - SetOutputFilter using lua is unstable
Summary: SetOutputFilter using lua is unstable
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_lua (show other bugs)
Version: 2.4.34
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-16 21:19 UTC by Frank
Modified: 2019-10-11 09:00 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frank 2018-09-16 21:19:37 UTC
The usage of mod_lua as an output filter seems to be very unstable:

LuaCodeCache forever
LuaScope thread
#LuaScope server
LuaOutputFilter MyOutputFilter "/opt/test/output-filter.lua" MyOutputFilter
SetOutputFilter MyOutputFilter

/opt/test/output-filter.lua:
function MyOutputFilter()
return
end

A quick check

# i=1;while [ $i -lt 10000 ]; do i=$[$i+1]; curl -sS -o /dev/null http://127.0.0.1:8080/index.html; if test $? -ne 0; then echo $i; fi; done

gives:

curl: (52) Empty reply from server
2575
curl: (52) Empty reply from server
2791
curl: (52) Empty reply from server
4586
curl: (52) Empty reply from server
5426
curl: (52) Empty reply from server
7907
curl: (52) Empty reply from server
7945
curl: (52) Empty reply from server
9237

and in error.log I see many lines like
[Sun Sep 16 18:44:43.944630 2018] [lua:crit] [pid 46228:tid 140320238941952] [client 127.0.0.1:46648] AH02329: lua: Unable to find entry function 'MyOutputFilter' in /opt/test/output-filter.lua (not a valid function)
[Sun Sep 16 18:44:43.948934 2018] [lua:crit] [pid 46228:tid 140320222156544] [client 127.0.0.1:46650] AH02329: lua: Unable to find entry function 'MyOutputFilter' in /opt/test/output-filter.lua (not a valid function)
[Sun Sep 16 18:44:43.953137 2018] [lua:crit] [pid 46228:tid 140320205371136] [client 127.0.0.1:46652] AH02329: lua: Unable to find entry function 'MyOutputFilter' in /opt/test/output-filter.lua (not a valid function)
[Sun Sep 16 18:44:43.957489 2018] [lua:crit] [pid 46228:tid 140320188585728] [client 127.0.0.1:46654] AH02329: lua: Unable to find entry function 'MyOutputFilter' in /opt/test/output-filter.lua (not a valid function)
[Sun Sep 16 18:44:44.421375 2018] [core:notice] [pid 46225:tid 140320530298752] AH00052: child pid 46228 exit signal Segmentation fault (11)


mod_whatkilledus shows:

**** Crash at 2018-09-16 18:44:43
Process id:  46228
Fatal signal: 11

/opt/test/httpd-2.4.34/modules/mod_backtrace.so:backtrace_get_backtrace+0x9F 0x7F9EE989C252
/opt/test/httpd-2.4.34/modules/mod_whatkilledus.so:write_report+0xCA 0x7F9EE9266B71
/opt/test/httpd-2.4.34/modules/mod_whatkilledus.so:whatkilledus_fatal_exception+0x132 0x7F9EE9266E30
/opt/test/httpd-2.4.34/bin/httpd:ap_run_fatal_exception+0x40 0x4330B0
/opt/test/httpd-2.4.34/bin/httpd:sig_coredump+0x89 0x45BF89
/lib64/libpthread.so.0:_L_unlock_13+0x34 0x7F9EEA2826D0
/lib64/liblua-5.1.so:lua_close+0xA71 0x7F9EE82041D1
/lib64/liblua-5.1.so:lua_close+0x1363 0x7F9EE8204AC3
/lib64/liblua-5.1.so:lua_close+0x2383 0x7F9EE8205AE3
/lib64/liblua-5.1.so:lua_getfield+0x5A 0x7F9EE81F7E9A
/opt/test/httpd-2.4.34/modules/mod_lua.so:lua_setup_filter_ctx.isra.17+0x153 0x7F9EE8429B13
/opt/test/httpd-2.4.34/modules/mod_lua.so:lua_output_filter_handle+0x23C 0x7F9EE842A32C
/opt/test/httpd-2.4.34/bin/httpd:default_handler+0x3E7 0x43EF57
/opt/test/httpd-2.4.34/bin/httpd:ap_run_handler+0x40 0x450200
/opt/test/httpd-2.4.34/bin/httpd:ap_invoke_handler+0x69 0x450749
/opt/test/httpd-2.4.34/bin/httpd:ap_process_async_request+0x1EA 0x465ECA
/opt/test/httpd-2.4.34/bin/httpd:ap_process_http_connection+0x1D1 0x462441
/opt/test/httpd-2.4.34/bin/httpd:ap_run_process_connection+0x40 0x459D30
/opt/test/httpd-2.4.34/modules/mod_mpm_event.so:process_socket+0x10A 0x7F9EE905C79A
/opt/test/httpd-2.4.34/modules/mod_mpm_event.so:worker_thread+0x3C4 0x7F9EE905DE84
/lib64/libpthread.so.0:start_thread+0xC5 0x7F9EEA27AE25
/lib64/libc.so.6:clone+0x6D 0x7F9EE9DA0BAD

Request line (unparsed):
GET /index.html HTTP/1.1
Request line (parsed):
GET :8080 /index.html
Request headers:
User-Agent:curl/7.29.0
Host:127.0.0.1%3a8080
Accept:*/*

Client connection:
127.0.0.1:46656->127.0.0.1:8080  (user agent at 127.0.0.1:46656)


(Almost) the same happens when I use 'LuaScope server' and/or using event/worker/prefork.

Any ideas what's wrong here?
Comment 1 Daniel Gruno 2019-01-25 21:46:59 UTC
This is likely a Lua VM cache issue, wherein it tries to run a script that isn't in memory. Try setting the following:

LuaCodeCache never

and see if that fixes things (by disabling caching of script files). If it does, I've got a good idea of where in the code to look
Comment 2 Frank 2019-10-11 08:58:29 UTC
Sure

LuaCodeCache never

removes the crashes, but up to my understanding now the lua-code is getting compiled everytime a request comes in.
That def. not want I was dreaming of....
Comment 3 Frank 2019-10-11 09:00:32 UTC
Ops I forget to set status to NEW