Skip to content

Commit 53680cc

Browse files
committed
bugfix: cosocket connections from the connection pool might lead to segfaults if it is not used immediately. thanks xukaifu for reporting this as github issue openresty#108.
1 parent b175269 commit 53680cc

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/ngx_http_lua_socket.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3127,6 +3127,11 @@ ngx_http_lua_get_keepalive_peer(ngx_http_request_t *r, lua_State *L,
31273127
u->writer.limit = 0;
31283128
u->request_sent = 0;
31293129

3130+
#if 1
3131+
u->write_event_handler = ngx_http_lua_socket_dummy_handler;
3132+
u->read_event_handler = ngx_http_lua_socket_dummy_handler;
3133+
#endif
3134+
31303135
if (u->cleanup == NULL) {
31313136
cln = ngx_http_cleanup_add(r, 0);
31323137
if (cln == NULL) {

t/068-socket-keepalive.t

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ our $HtmlDir = html_dir;
1111

1212
$ENV{TEST_NGINX_CLIENT_PORT} ||= server_port();
1313
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
14+
#$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
15+
16+
$ENV{LUA_PATH} ||=
17+
'/usr/local/openresty-debug/lualib/?.lua;/usr/local/openresty/lualib/?.lua;;';
1418

1519
no_long_string();
1620
#no_diff();
@@ -848,3 +852,50 @@ received response of 119 bytes
848852
["lua socket get keepalive peer: using connection",
849853
'lua socket keepalive create connection pool for key "unix:/tmp/test-nginx.sock"']
850854

855+
856+
857+
=== TEST 12: github issue #108: ngx.locaiton.capture + redis.set_keepalive
858+
--- http_config eval
859+
qq{
860+
lua_package_path "$::HtmlDir/?.lua;;";
861+
}
862+
--- config
863+
location /t {
864+
default_type text/html;
865+
set $port $TEST_NGINX_MEMCACHED_PORT;
866+
#lua_code_cache off;
867+
lua_need_request_body on;
868+
content_by_lua_file html/t.lua;
869+
}
870+
871+
location /anyurl {
872+
internal;
873+
proxy_pass http://127.0.0.1:$server_port/dummy;
874+
}
875+
876+
location = /dummy {
877+
echo dummy;
878+
}
879+
--- user_files
880+
>>> t.lua
881+
local sock, err = ngx.socket.connect("127.0.0.1", ngx.var.port)
882+
if not sock then ngx.say(err) return end
883+
sock:send("flush_all\r\n")
884+
sock:receive()
885+
sock:setkeepalive()
886+
887+
sock, err = ngx.socket.connect("127.0.0.1", ngx.var.port)
888+
if not sock then ngx.say(err) return end
889+
local res = ngx.location.capture("/anyurl") --3
890+
891+
ngx.say("ok")
892+
--- request
893+
GET /t
894+
--- response_body
895+
ok
896+
--- error_log
897+
lua socket get keepalive peer: using connection
898+
--- no_error_log
899+
[error]
900+
[alert]
901+

0 commit comments

Comments
 (0)