Greetings.
Caddy returns me 502 Bad Gateway
when I'm trying to query an endpoint that caddy should proxy to an uwsgi server via uwsgi native protocol. I have boiled down the problem to minimal reproducible example: https://github.com/norohind/caddy-uwsgi-transport.
So, that how it looks from client side (-D - makes curl print out headers to stdout):
$ curl -D - http://127.0.0.1:8888
HTTP/1.1 502 Bad Gateway
Server: Caddy
Date: Tue, 28 Nov 2023 19:25:55 GMT
Content-Length: 0
At the same time in logs of caddy and uwsgi appear following lines
caddy-uwsgi-transport-issue-uwsgi-1 | [pid: 1|app: 0|req: 6/6] 172.22.0.1:57030 () {32 vars in 378 bytes} [Tue Nov 28 19:25:55 2023] GET => generated 11 bytes in 0 msecs (HTTP/1.1 200) 1 headers in 43 bytes (4 switches on core 0)
caddy-uwsgi-transport-issue-caddy-1 | {"level":"error","ts":1701199555.950834,"logger":"http.log.error","msg":"malformed HTTP version \"Status:\"","request":{"remote_ip":"172.22.0.1","remote_port":"57030","client_ip":"172.22.0.1","proto":"HTTP/1.1","method":"GET","host":"127.0.0.1:8888","uri":"/","headers":{"User-Agent":["curl/8.4.0"],"Accept":["*/*"]}},"duration":0.001092797,"status":502,"err_id":"verjzexi7","err_trace":"reverseproxy.statusError (reverseproxy.go:1265)"}
As it can be seen, uwsgi receives the query and appears to respond, but caddy, for some reason, can't handle the response and thus returns to http query 502 code.
Most interesting part is this problem occurs only if uwsgi is run with config file (uwsgi.conf in the example). If you would
run uwsgi with cli args then everything works fine. Conveniently, in the example, I left an option to run uwsgi with the same parameters as in uwsgi.conf but as cli args (Details in Steps to reproduce).
Steps to reproduce
git clone https://github.com/norohind/caddy-uwsgi-transport.git
cd caddy-uwsgi-transport
docker-compose up # This one shall build images and then run containers, logs going to be on stdout
# Now in separate shell query the uwsgi app through caddy
curl -D - http://127.0.0.1:8888
Mystery with "equivalence" of cli args and config file
In docker-compose.yaml: Comment in line 22 and comment out line 21, then make docker-compose up --build
.
Then query caddy again using curl and you should get 200 http response, although options provided to uwsgi in both cases seems to be identical.
Versions
- caddy-uwsgi-transport: I believe it builds from the latest commit, as for now it is
573bdc411df6d73ea72730cd755324bbb3a0151b
- Uwsgi (from logs): uWSGI 2.0.23 (64bit)
Caddy -v
: v2.7.5 h1:HoysvZkLcN2xJExEepaFHK92Qgs7xAiCFydN5x5Hs6Q=
docker version
:
Client:
Version: 24.0.7
API version: 1.43
Go version: go1.21.3
Git commit: tag v24.0.7
Built: Wed Nov 1 19:52:11 2023
OS/Arch: linux/amd64
Context: default
Server:
Engine:
Version: 24.0.7
API version: 1.43 (minimum version 1.12)
Go version: go1.21.3
Git commit: tag v24.0.7
Built: Wed Nov 1 19:52:11 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.7.8
GitCommit: UNSET
runc:
Version: 1.1.9
GitCommit:
docker-init:
Version: 0.19.0
GitCommit:
docker-compose -v
: Docker Compose version v2.21.0