From 48c73d6100632d397cef24e36763b36be65efcd6 Mon Sep 17 00:00:00 2001 From: jiahao Date: Thu, 11 Jul 2024 18:39:40 +0800 Subject: [PATCH] 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) #1 0x00007ff596f623d2 lj_cf_ffi_string (libluajit-5.1.so.2 + 0x523d2) #2 0x00007ff596f1bb4b lj_BC_FUNCC (libluajit-5.1.so.2 + 0xbb4b) #3 0x00007ff596f74223 lua_pcall (libluajit-5.1.so.2 + 0x64223) #4 0x00000000005044b7 n/a (/home/jiahao/work/org/lua-resty-core/work/nginx/sbin/nginx + 0x1044b7) ``` --- lib/ngx/balancer.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ngx/balancer.lua b/lib/ngx/balancer.lua index 18bdc2cbf..2aa54955e 100644 --- a/lib/ngx/balancer.lua +++ b/lib/ngx/balancer.lua @@ -35,8 +35,8 @@ if subsystem == 'http' then ffi.cdef[[ int ngx_http_lua_ffi_balancer_set_current_peer(ngx_http_request_t *r, const unsigned char *addr, size_t addr_len, int port, - const unsigned char *host, ssize_t host_len, - char **err); + char **err, + const unsigned char *host, ssize_t host_len); int ngx_http_lua_ffi_balancer_enable_keepalive(ngx_http_request_t *r, unsigned long timeout, unsigned int max_requests, char **err); @@ -162,9 +162,9 @@ if subsystem == "http" then local rc = ngx_lua_ffi_balancer_set_current_peer(r, addr, #addr, port, + errmsg, host, - host and #host or 0, - errmsg) + host and #host or 0) if rc == FFI_OK then return true end