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

   ### Description
   
   When APISIX listens on a unix domain socket (e.g. added via 
`nginx_config.http_server_configuration_snippet`), calling the batch-requests 
endpoint over that socket fails with:
   
   ```json
   {"error_msg":"connect to apisix failed: missing the port number"}
   ```
   
   The plugin loops the pipelined requests back to APISIX itself with 
`httpc:connect("127.0.0.1", ngx.var.server_port)`, but nginx renders 
`$server_port` as an empty string for a request that arrived over a unix 
socket. The empty string is neither a number nor a `unix:` prefixed host, so 
lua-nginx-module's `tcpsock:connect()` rejects it with `missing the port 
number`; resty.http passes that through and the plugin turns it into the 500 
above.
   
   This PR makes the loopback connect fall back to the first TCP port found in 
`apisix.node_listen` when `$server_port` is empty. The value read from the 
local conf is not normalized by the CLI, so both config forms are handled: a 
plain port number, and an array of port numbers or `{ip, port}` tables. If no 
TCP port can be resolved at all, the plugin returns a 503 explaining that 
batch-requests needs a TCP listener to loop back requests.
   
   An alternative would be to connect back over the unix socket itself, but the 
listening socket path is not exposed through any nginx variable, so that is 
left as possible future work.
   
   This revives #13530, which was closed by its author while still a draft and 
never reviewed. The plugin change is unchanged from that branch; the regression 
test was reworked to build the request body with `core.json.encode` instead of 
an inlined long-bracket JSON string, which can trip the nginx config parser 
when the block crosses a config-buffer boundary.
   
   Added a regression test that injects an extra `listen unix:` listener into 
the test server and sends the batch-requests call over it.
   
   Test status: the code passes `luajit -bl` syntax checking and `luacheck`. I 
have not run the test-nginx suite locally; relying on CI for that.
   
   #### Which issue(s) this PR fixes:
   
   Fixes #11781
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [x] 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)


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to