I encountered a case where I was getting 502 (Bad Gateway) responses when I was testing what happens when I take down one of the targets (out of two). seems to me like this should not happen as all traffic should be routed to the remaining target.
(I’m replacing the URLs to not have the protocol because of the limit of 5 URLs when posting a message)
So I set up a basic test case for it and I can replicate it very easily :
-
using docker kong 0.13.1 running on a mac with a Cassandra DB (also docker)
-
Create upstream:
curl -X POST localhost:8801/upstreams -H"Content-Type:application/json" -d’{“name”:“test.upstream”, “healthchecks.active.http_path”:"/", “healthchecks.active.healthy.interval”:60, “healthchecks.active.healthy.http_statuses”:[200], “healthchecks.active.healthy.successes”:2 ,“healthchecks.active.unhealthy.interval”:30}’ -
Create targets:
curl -X POST localhost:8801/upstreams/test.upstream/targets -H"Content-Type:application/json" -d’{“target”:“docker.for.mac.localhost:5555”, “weight”:100}’
curl -X POST localhost:8801/upstreams/test.upstream/targets -H"Content-Type:application/json" -d’{“target”:“docker.for.mac.localhost:5556”, “weight”:100}’ -
Create service:
curl -X POST localhost:8801/services/ -H"Content-Type:application/json" -d’{“name”:“test.the.upstream”, “url”:“http://test.upstream”}’ -
Create route:
curl -X POST localhost:8801/services/test.the.upstream/routes -H"Content-Type:application/json" -d’{“paths”:["/index.html"],“preserve_host”:true, “strip_path”:false}’ -
Create index.html in a folder:
mkdir simpleServer
cd simpleServer
echo “HELLO” > index.html -
Run two simpleHTTPServers in the folder above:
python -m SimpleHTTPServer 5555
python -m SimpleHTTPServer 5556 -
Test that the targets work:
curl localhost:5555/index.html HELLO curl localhost:5556/index.html
HELLO -
Test that Kong works:
$ curl localhost:8000/index.html
HELLO -
Run that same curl in a loop against Kong:
$ while :; do curl -s localhost:8000/index.html | tr ‘\n’ ‘,’; done
HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO, -
Run the same curl in a loop against Kong but while is running, stop one of the simpleHTTPServers. I’d expect to get the same output - a bunch of "HELLO"s but instead I get some “An invalid response was received from the upstream server” responses in there:
$ while :; do curl -s localhost:8000/index.html | tr ‘\n’ ‘,’; done
HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,An invalid response was received from the upstream server,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,An invalid response was received from the upstream server,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,An invalid response was received from the upstream server,HELLO,HELLO,HELLO,An invalid response was received from the upstream server,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO,HELLO, -
Start the stopped simpleHTTPServer and notice that there are no more “errors” reported and only "HELLO"s are showing
Did I configure anything wrong? Because this feels like too simple of a config to break that easily…