fix(batch-requests): missing the port number error when APISIX listens on a unix socket#13530
Draft
nic-6443 wants to merge 1 commit into
Draft
fix(batch-requests): missing the port number error when APISIX listens on a unix socket#13530nic-6443 wants to merge 1 commit into
nic-6443 wants to merge 1 commit into
Conversation
…es via unix socket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When APISIX listens on a unix domain socket (e.g. behind a sidecar or local proxy via
nginx_config.http_server_configuration_snippet), calling the batch-requests endpoint fails with:{"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's$server_portis an empty string when the inbound request arrived over a unix socket, so the connect fails.This PR makes the loopback connect fall back to the first TCP port found in
apisix.node_listenfrom the local config when$server_portis empty. Since the value in the local conf is not normalized by the CLI, 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 now returns a clear 503 explaining that batch-requests needs a TCP listener to loop back requests.This follows the direction explored in the PoC #11782 (falling back to
node_listen). 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.Added a regression test that injects an extra
listen unix:listener into the test server and sends the batch-requests call over it: it fails with themissing the port numbererror before the fix and passes after.Which issue(s) this PR fixes:
Fixes #11781
Checklist