From c63ab484f73dbdc4421e44421e4c1195747848af Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Tue, 27 Oct 2026 07:37:42 +0800 Subject: [PATCH] fix: return health check module on repeated init --- lib/resty/etcd/health_check.lua | 3 +++ t/v3/health_check.t | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/resty/etcd/health_check.lua b/lib/resty/etcd/health_check.lua index 88aa3018..55911e65 100644 --- a/lib/resty/etcd/health_check.lua +++ b/lib/resty/etcd/health_check.lua @@ -163,6 +163,9 @@ function _M.init(opts) _M.conf = conf return _M, nil end + + -- Keep the existing configuration when the health-check mode is unchanged. + return _M, nil end return _M diff --git a/t/v3/health_check.t b/t/v3/health_check.t index 7c3f3b45..463df7a8 100644 --- a/t/v3/health_check.t +++ b/t/v3/health_check.t @@ -957,3 +957,30 @@ GET /t choose_endpoint(): choose endpoint: http://127.0.0.1:12379 choose_endpoint(): choose endpoint: http://127.0.0.1:22379 choose_endpoint(): choose endpoint: http://127.0.0.1:32379 + + +=== TEST 23: repeated health-check initialization returns the module +--- http_config eval: $::HttpConfig +--- config + location /t { + content_by_lua_block { + local health_check = require("resty.etcd.health_check") + local first, first_err = health_check.init({ + shm_name = "etcd_cluster_health_check", + }) + assert(first == health_check and first_err == nil) + + local second, second_err = health_check.init({ + shm_name = "etcd_cluster_health_check", + }) + assert(second == health_check and second_err == nil) + + ngx.say("done") + } + } +--- request +GET /t +--- response_body +done +--- no_error_log +[error]