This is an automated email from the ASF dual-hosted git repository.
nic-6443 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 4762c33ff fix(ai-proxy-multi): resolve _dns_value in
construct_upstream when nil (#13322)
4762c33ff is described below
commit 4762c33ff920168f5646a1a05b95590af53a7331
Author: Nic <[email protected]>
AuthorDate: Thu Apr 30 12:00:48 2026 +0800
fix(ai-proxy-multi): resolve _dns_value in construct_upstream when nil
(#13322)
---
apisix/plugins/ai-proxy-multi.lua | 6 ++++-
t/plugin/ai-proxy-multi3.t | 47 +++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/apisix/plugins/ai-proxy-multi.lua
b/apisix/plugins/ai-proxy-multi.lua
index 419af6aaa..a21c477eb 100644
--- a/apisix/plugins/ai-proxy-multi.lua
+++ b/apisix/plugins/ai-proxy-multi.lua
@@ -439,7 +439,11 @@ function _M.construct_upstream(instance)
local upstream = {}
local node = instance._dns_value
if not node then
- return nil, "failed to resolve endpoint for instance: " ..
instance.name
+ resolve_endpoint(instance)
+ node = instance._dns_value
+ if not node then
+ return nil, "failed to resolve endpoint for instance: " ..
instance.name
+ end
end
if not node.host or not node.port then
diff --git a/t/plugin/ai-proxy-multi3.t b/t/plugin/ai-proxy-multi3.t
index faeb33c91..21930b0d1 100644
--- a/t/plugin/ai-proxy-multi3.t
+++ b/t/plugin/ai-proxy-multi3.t
@@ -1060,3 +1060,50 @@ failed to get health check target status
--- error_log
releasing existing checker
--- timeout: 5
+
+
+
+=== TEST 14: construct_upstream resolves _dns_value when nil (config table
replacement scenario)
+--- config
+ location /t {
+ content_by_lua_block {
+ local plugin = require("apisix.plugins.ai-proxy-multi")
+
+ -- Simulate an instance after config table replacement: _dns_value
is lost
+ local instance = {
+ name = "test-instance",
+ provider = "openai",
+ weight = 1,
+ priority = 0,
+ override = {
+ endpoint = "https://127.0.0.1:443",
+ },
+ auth = {
+ header = {
+ Authorization = "Bearer test-key",
+ },
+ },
+ }
+
+ -- Confirm _dns_value is nil (simulating config table replacement)
+ assert(instance._dns_value == nil, "_dns_value should be nil
initially")
+
+ -- construct_upstream should resolve _dns_value as fallback
+ local upstream, err = plugin.construct_upstream(instance)
+ if not upstream then
+ ngx.say("FAIL: " .. err)
+ return
+ end
+
+ -- Verify _dns_value was populated
+ assert(instance._dns_value ~= nil, "_dns_value should be set after
construct_upstream")
+
+ ngx.say("host: ", upstream.nodes[1].host)
+ ngx.say("port: ", upstream.nodes[1].port)
+ ngx.say("passed")
+ }
+ }
+--- response_body
+host: 127.0.0.1
+port: 443
+passed