You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "hachi029 (via GitHub)" <gi...@apache.org> on 2025/11/26 14:07:19 UTC

[PR] batch-request: the number of sub responses does not match the number of sub requests [apisix]

hachi029 opened a new pull request, #12779:
URL: https://github.com/apache/apisix/pull/12779

   
   ### Description
   
   when there is any timeout sub request, the number of sub responses does not match the number of sub requests。
   
   for example: 
   
    the batch-request with 2 sub requests
   `{"headers":{},"pipeline":[{"path":"/quick","method":"GET"},{"path":"/slow","method":"GET"}]}`
   
   there are 3  sub responses in the batch-response,  with an extra empty json empty '{}'
   `[{"status":200,"body":"quick","reason":"OK","headers":{"Connection":"keep-alive"}},{"status":504,"reason":"upstream timeout"},{}]`
   
   ### Checklist
   
   - [ ] I have explained the need for this PR and the problem it solves
   - [ ] I have explained the changes or the new features added to this PR
   - [ ] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [ ] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
   
   <!--
   
   Note
   
   1. Mark the PR as draft until it's ready to be reviewed.
   2. Always add/update tests for any changes unless you have a good reason.
   3. Always update the documentation to reflect the changes made in the PR.
   4. Make a new commit to resolve conversations instead of `push -f`.
   5. To resolve merge conflicts, merge master instead of rebasing.
   6. Use "request review" to notify the reviewer after making changes.
   7. Only a reviewer can mark a conversation as resolved.
   
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(batch-requests): the number of sub-responses does not match that of sub-requests [apisix]

Posted by "Baoyuantop (via GitHub)" <gi...@apache.org>.
Baoyuantop commented on PR #12779:
URL: https://github.com/apache/apisix/pull/12779#issuecomment-3654461327

   Hi @hachi029, could you merge the latest main branch to make CI pass?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(batch-requests): the number of sub-responses does not match that of sub-requests [apisix]

Posted by "Baoyuantop (via GitHub)" <gi...@apache.org>.
Baoyuantop merged PR #12779:
URL: https://github.com/apache/apisix/pull/12779


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(batch-requests): the number of sub-responses does not match that of sub-requests [apisix]

Posted by "hachi029 (via GitHub)" <gi...@apache.org>.
hachi029 commented on code in PR #12779:
URL: https://github.com/apache/apisix/pull/12779#discussion_r2638561606


##########
t/plugin/batch-requests2.t:
##########
@@ -444,3 +444,52 @@ 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 code, body, res_body, res_header = t('/apisix/batch-requests',
+                 ngx.HTTP_POST,
+                 [=[{
+                    "headers": {
+                    },
+                    "timeout": 200,
+                    "pipeline":[
+                    {
+                        "path": "/ok",
+                        "method": "GET"
+                    },{
+                      "path": "/timeout",
+                      "method": "GET"
+                    }]
+                }]=])
+            -- core.log.warn("res_body:", res_body)
+            ngx.status = code
+            -- print the number of sub-responses.
+            -- the number is expected to be the same as that of the sub-requests.
+            ngx.say(#cjson.decode(res_body))
+        }
+    }
+
+    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
+2

Review Comment:
   @membphis @Baoyuantop Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(batch-requests): the number of sub responses does not match the number of sub requests [apisix]

Posted by "hachi029 (via GitHub)" <gi...@apache.org>.
hachi029 commented on code in PR #12779:
URL: https://github.com/apache/apisix/pull/12779#discussion_r2567382050


##########
t/plugin/batch-requests2.t:
##########
@@ -444,3 +444,52 @@ 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 code, body, res_body, res_header = t('/apisix/batch-requests',
+                 ngx.HTTP_POST,
+                 [=[{
+                    "headers": {
+                    },
+                    "timeout": 200,
+                    "pipeline":[
+                    {
+                        "path": "/ok",
+                        "method": "GET"
+                    },{
+                      "path": "/timeout",
+                      "method": "GET"
+                    }]
+                }]=])
+            -- core.log.warn("res_body:", res_body)

Review Comment:
   Ok, I will delete it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(batch-requests): the number of sub-responses does not match that of sub-requests [apisix]

Posted by "membphis (via GitHub)" <gi...@apache.org>.
membphis commented on code in PR #12779:
URL: https://github.com/apache/apisix/pull/12779#discussion_r2634303430


##########
t/plugin/batch-requests2.t:
##########
@@ -444,3 +444,52 @@ 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 code, body, res_body, res_header = t('/apisix/batch-requests',
+                 ngx.HTTP_POST,
+                 [=[{
+                    "headers": {
+                    },
+                    "timeout": 200,
+                    "pipeline":[
+                    {
+                        "path": "/ok",
+                        "method": "GET"
+                    },{
+                      "path": "/timeout",
+                      "method": "GET"
+                    }]
+                }]=])
+            -- core.log.warn("res_body:", res_body)
+            ngx.status = code
+            -- print the number of sub-responses.
+            -- the number is expected to be the same as that of the sub-requests.
+            ngx.say(#cjson.decode(res_body))
+        }
+    }
+
+    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
+2

Review Comment:
   for me, i think we can print two status which is much clear.
   
   like this:
   ```
   1th response code: 200
   2th response code: 504
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(batch-requests): the number of sub-responses does not match that of sub-requests [apisix]

Posted by "hachi029 (via GitHub)" <gi...@apache.org>.
hachi029 commented on PR #12779:
URL: https://github.com/apache/apisix/pull/12779#issuecomment-3654537245

   @Baoyuantop merged


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(batch-requests): the number of sub responses does not match the number of sub requests [apisix]

Posted by "Baoyuantop (via GitHub)" <gi...@apache.org>.
Baoyuantop commented on code in PR #12779:
URL: https://github.com/apache/apisix/pull/12779#discussion_r2567083145


##########
t/plugin/batch-requests2.t:
##########
@@ -444,3 +444,52 @@ 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 code, body, res_body, res_header = t('/apisix/batch-requests',
+                 ngx.HTTP_POST,
+                 [=[{
+                    "headers": {
+                    },
+                    "timeout": 200,
+                    "pipeline":[
+                    {
+                        "path": "/ok",
+                        "method": "GET"
+                    },{
+                      "path": "/timeout",
+                      "method": "GET"
+                    }]
+                }]=])
+            -- core.log.warn("res_body:", res_body)

Review Comment:
   Do we need this line?



##########
t/plugin/batch-requests2.t:
##########
@@ -444,3 +444,52 @@ 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 code, body, res_body, res_header = t('/apisix/batch-requests',
+                 ngx.HTTP_POST,
+                 [=[{
+                    "headers": {
+                    },
+                    "timeout": 200,
+                    "pipeline":[
+                    {
+                        "path": "/ok",
+                        "method": "GET"
+                    },{
+                      "path": "/timeout",
+                      "method": "GET"
+                    }]
+                }]=])
+            -- core.log.warn("res_body:", res_body)
+            ngx.status = code
+            -- print the number of sub-responses.
+            -- the number is expected to be the same as that of the sub-requests.
+            ngx.say(#cjson.decode(res_body))
+        }
+    }
+
+    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
+2

Review Comment:
   It is recommended to check the specific content, such as the status.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(batch-requests): the number of sub-responses does not match that of sub-requests [apisix]

Posted by "Baoyuantop (via GitHub)" <gi...@apache.org>.
Baoyuantop commented on PR #12779:
URL: https://github.com/apache/apisix/pull/12779#issuecomment-3684800341

   @membphis  The comment has been resolved. Please review it again.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(batch-requests): the number of sub-responses does not match that of sub-requests [apisix]

Posted by "membphis (via GitHub)" <gi...@apache.org>.
membphis commented on code in PR #12779:
URL: https://github.com/apache/apisix/pull/12779#discussion_r2634303430


##########
t/plugin/batch-requests2.t:
##########
@@ -444,3 +444,52 @@ 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 code, body, res_body, res_header = t('/apisix/batch-requests',
+                 ngx.HTTP_POST,
+                 [=[{
+                    "headers": {
+                    },
+                    "timeout": 200,
+                    "pipeline":[
+                    {
+                        "path": "/ok",
+                        "method": "GET"
+                    },{
+                      "path": "/timeout",
+                      "method": "GET"
+                    }]
+                }]=])
+            -- core.log.warn("res_body:", res_body)
+            ngx.status = code
+            -- print the number of sub-responses.
+            -- the number is expected to be the same as that of the sub-requests.
+            ngx.say(#cjson.decode(res_body))
+        }
+    }
+
+    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
+2

Review Comment:
   for me, i think we can print two status which is much clear.
   
   like this:
   ```
   1th response code: 200
   1th response code: 504
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(batch-requests): the number of sub-responses does not match that of sub-requests [apisix]

Posted by "Baoyuantop (via GitHub)" <gi...@apache.org>.
Baoyuantop commented on code in PR #12779:
URL: https://github.com/apache/apisix/pull/12779#discussion_r2634347522


##########
t/plugin/batch-requests2.t:
##########
@@ -444,3 +444,52 @@ 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 code, body, res_body, res_header = t('/apisix/batch-requests',
+                 ngx.HTTP_POST,
+                 [=[{
+                    "headers": {
+                    },
+                    "timeout": 200,
+                    "pipeline":[
+                    {
+                        "path": "/ok",
+                        "method": "GET"
+                    },{
+                      "path": "/timeout",
+                      "method": "GET"
+                    }]
+                }]=])
+            -- core.log.warn("res_body:", res_body)
+            ngx.status = code
+            -- print the number of sub-responses.
+            -- the number is expected to be the same as that of the sub-requests.
+            ngx.say(#cjson.decode(res_body))
+        }
+    }
+
+    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
+2

Review Comment:
   Hi @hachi029, please check this comment, thanks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(batch-requests): the number of sub responses does not match the number of sub requests [apisix]

Posted by "hachi029 (via GitHub)" <gi...@apache.org>.
hachi029 commented on code in PR #12779:
URL: https://github.com/apache/apisix/pull/12779#discussion_r2567404957


##########
t/plugin/batch-requests2.t:
##########
@@ -444,3 +444,52 @@ 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 code, body, res_body, res_header = t('/apisix/batch-requests',
+                 ngx.HTTP_POST,
+                 [=[{
+                    "headers": {
+                    },
+                    "timeout": 200,
+                    "pipeline":[
+                    {
+                        "path": "/ok",
+                        "method": "GET"
+                    },{
+                      "path": "/timeout",
+                      "method": "GET"
+                    }]
+                }]=])
+            -- core.log.warn("res_body:", res_body)
+            ngx.status = code
+            -- print the number of sub-responses.
+            -- the number is expected to be the same as that of the sub-requests.
+            ngx.say(#cjson.decode(res_body))
+        }
+    }
+
+    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
+2

Review Comment:
   the original response contains variables such as  Date header like : `[{"body":"ok","headers":{"Server":"openresty/1.27.1.2","Content-Type":"text/plain","Date":"Thu,` 27 Nov 2025 06:46:49 GMT","Connection":"keep-alive","Transfer-Encoding":"chunked"},"status":200,"reason":"OK"},{"status":504,"reason":"upstream timeout"}]', so it is not easy to compare the original content.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org