This is an automated email from the ASF dual-hosted git repository.
baoyuan 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 9cca42ee9 fix(batch-requests): the number of sub-responses does not
match that of sub-requests (#12779)
9cca42ee9 is described below
commit 9cca42ee9e377aa730c194af43a672b23038edef
Author: hachi029 <[email protected]>
AuthorDate: Tue Dec 23 22:42:55 2025 +0800
fix(batch-requests): the number of sub-responses does not match that of
sub-requests (#12779)
---
apisix/plugins/batch-requests.lua | 2 ++
t/plugin/batch-requests2.t | 51 +++++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+)
diff --git a/apisix/plugins/batch-requests.lua
b/apisix/plugins/batch-requests.lua
index a1b574307..fed04cb3b 100644
--- a/apisix/plugins/batch-requests.lua
+++ b/apisix/plugins/batch-requests.lua
@@ -268,6 +268,7 @@ local function batch_requests(ctx)
status = 504,
reason = "upstream timeout"
})
+ goto CONTINUE
end
local sub_resp = {
status = resp.status,
@@ -285,6 +286,7 @@ local function batch_requests(ctx)
end
end
core.table.insert(aggregated_resp, sub_resp)
+ ::CONTINUE::
end
return 200, aggregated_resp
end
diff --git a/t/plugin/batch-requests2.t b/t/plugin/batch-requests2.t
index b7ac1c6d9..9419c580e 100644
--- a/t/plugin/batch-requests2.t
+++ b/t/plugin/batch-requests2.t
@@ -444,3 +444,54 @@ POST /apisix/batch-requests
}
--- response_headers
Content-Type: application/json
+
+
+
+=== TEST 11: Ensure sub_responses count matches sub_requests on timed out
sub_request (contains no empty json object like '{}' in batch response)
+--- config
+ location = /aggregate {
+ content_by_lua_block {
+ local cjson = require("cjson.safe")
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local _, _, batch_responses_str = t('/apisix/batch-requests',
+ ngx.HTTP_POST,
+ [=[{
+ "headers": {
+ },
+ "timeout": 200,
+ "pipeline":[
+ {
+ "path": "/ok",
+ "method": "GET"
+ },{
+ "path": "/timeout",
+ "method": "GET"
+ }]
+ }]=])
+ local batch_responses = cjson.decode(batch_responses_str)
+ -- there are expected to be only 2 responses in batch_responses
+ for idx, response in ipairs(batch_responses) do
+ ngx.say(idx, "th response code: ", response.status)
+ end
+ }
+ }
+
+ location = /ok {
+ content_by_lua_block {
+ ngx.print("ok")
+ }
+ }
+ location = /timeout {
+ content_by_lua_block {
+ ngx.sleep(1)
+ ngx.print("timeout")
+ }
+ }
+--- request
+GET /aggregate
+--- error_log
+timeout
+--- response_body
+1th response code: 200
+2th response code: 504