apache / apache/apisix

bug: batch-requests plugin: "connect to apisix failed: missing the port number" when connecting via unix socket

Open
#11,781 1 comment 0 reactions 0 assignees View on GitHub
bug plugin
Dominant language
Lua
Stars
17.1k
Forks
2.9k
Avg merge
3d 16h
Merged PRs (30d)
63

Description

### Current Behavior

If you configure Nginx to listen on a unix socket:
```yaml
nginx_config:
http_server_configuration_snippet: |
listen unix:/run/sockets/apisix_http;
```
And then make a request that is handled by the batch-requests plugin, you get the following error:
```
connect to apisix failed: missing the port number
```

This is because the batch-requests plugin uses the `ngx.var.server_port` variable when setting up the internal request, assuming that it is populated with a port number. If the client connection came over a unix listening socket, `ngx.var.server_port` is a zero length string.

### Expected Behavior

I get that unix sockets are probably an edge case but it would be nice if this worked.

I will submit a PR shortly with my modified `batch-requests.lua` that checks for this condition and then gets the `server_port` from the `node_listen` property of the APISIX configuration.

### Error Logs

_No response_

### Steps to Reproduce

* Use the latest docker image
* Configure nginx (via apisix config.yml) to listen on a unix socket:
```yaml
nginx_config:
http_server_configuration_snippet: |
listen unix:/run/sockets/apisix_http;
```
* Configure the batch-requests plugin
* Issue a batch-request via the unix socket:
`curl --unix-socket /run/sockets/apisix_http http://127.0.0.1:9080/your_url --data '{}'`

### Environment

- APISIX version: 3.11.0
- Operating system:
- OpenResty / Nginx version: openresty/1.25.3.2
- etcd version: Using Standalone mode
- APISIX Dashboard version, if relevant: Dashboard not in use
- Plugin runner version, for issues related to plugin runners: N/A
- LuaRocks version, for installation issues (run `luarocks --version`): N/A

Contributor guide

Open the contributing guide

Research direction

Start by reading the batch-requests.lua plugin code where ngx.var.server_port is used to construct the internal request, then inspect how the APISIX node_listen configuration is represented. Reproduce the unix-socket request from the issue and verify that batch requests no longer fail with a missing-port error while normal port-based requests continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.