Skip to content

Commit fbe3e48

Browse files
author
jiahao
committed
bugfix: append new parameters to ngx_lua_ffi_balancer_set_current_peer at function end.
Avoid inserting new parameters in the middle of the function to prevent core dumps when using old lua-resty-core with new lua-nginx-module. Example stack trace: ``` Message: Process 1414245 (nginx) of user 1000 dumped core. Stack trace of thread 1414245: #0 0x00007ff596938285 __strlen_avx2 (libc.so.6 + 0x162285) openresty#1 0x00007ff596f623d2 lj_cf_ffi_string (libluajit-5.1.so.2 + 0x523d2) openresty#2 0x00007ff596f1bb4b lj_BC_FUNCC (libluajit-5.1.so.2 + 0xbb4b) openresty#3 0x00007ff596f74223 lua_pcall (libluajit-5.1.so.2 + 0x64223) openresty#4 0x00000000005044b7 n/a (/home/jiahao/work/org/lua-resty-core/work/nginx/sbin/nginx + 0x1044b7) ```
1 parent a4297a0 commit fbe3e48

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/ngx/balancer.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ if subsystem == 'http' then
3535
ffi.cdef[[
3636
int ngx_http_lua_ffi_balancer_set_current_peer(ngx_http_request_t *r,
3737
const unsigned char *addr, size_t addr_len, int port,
38-
const unsigned char *host, ssize_t host_len,
39-
char **err);
38+
char **err,
39+
const unsigned char *host, ssize_t host_len);
4040

4141
int ngx_http_lua_ffi_balancer_enable_keepalive(ngx_http_request_t *r,
4242
unsigned long timeout, unsigned int max_requests, char **err);
@@ -162,9 +162,9 @@ if subsystem == "http" then
162162

163163
local rc = ngx_lua_ffi_balancer_set_current_peer(r, addr, #addr,
164164
port,
165+
errmsg,
165166
host,
166-
host and #host or 0,
167-
errmsg)
167+
host and #host or 0)
168168
if rc == FFI_OK then
169169
return true
170170
end

0 commit comments

Comments
 (0)