Skip to content

Commit 9cca42e

Browse files
authored
fix(batch-requests): the number of sub-responses does not match that of sub-requests (#12779)
1 parent e9d194a commit 9cca42e

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

apisix/plugins/batch-requests.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ local function batch_requests(ctx)
268268
status = 504,
269269
reason = "upstream timeout"
270270
})
271+
goto CONTINUE
271272
end
272273
local sub_resp = {
273274
status = resp.status,
@@ -285,6 +286,7 @@ local function batch_requests(ctx)
285286
end
286287
end
287288
core.table.insert(aggregated_resp, sub_resp)
289+
::CONTINUE::
288290
end
289291
return 200, aggregated_resp
290292
end

t/plugin/batch-requests2.t

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,3 +444,54 @@ POST /apisix/batch-requests
444444
}
445445
--- response_headers
446446
Content-Type: application/json
447+
448+
449+
450+
=== TEST 11: Ensure sub_responses count matches sub_requests on timed out sub_request (contains no empty json object like '{}' in batch response)
451+
--- config
452+
location = /aggregate {
453+
content_by_lua_block {
454+
local cjson = require("cjson.safe")
455+
local core = require("apisix.core")
456+
local t = require("lib.test_admin").test
457+
local _, _, batch_responses_str = t('/apisix/batch-requests',
458+
ngx.HTTP_POST,
459+
[=[{
460+
"headers": {
461+
},
462+
"timeout": 200,
463+
"pipeline":[
464+
{
465+
"path": "/ok",
466+
"method": "GET"
467+
},{
468+
"path": "/timeout",
469+
"method": "GET"
470+
}]
471+
}]=])
472+
local batch_responses = cjson.decode(batch_responses_str)
473+
-- there are expected to be only 2 responses in batch_responses
474+
for idx, response in ipairs(batch_responses) do
475+
ngx.say(idx, "th response code: ", response.status)
476+
end
477+
}
478+
}
479+
480+
location = /ok {
481+
content_by_lua_block {
482+
ngx.print("ok")
483+
}
484+
}
485+
location = /timeout {
486+
content_by_lua_block {
487+
ngx.sleep(1)
488+
ngx.print("timeout")
489+
}
490+
}
491+
--- request
492+
GET /aggregate
493+
--- error_log
494+
timeout
495+
--- response_body
496+
1th response code: 200
497+
2th response code: 504

0 commit comments

Comments
 (0)