Shopify / toxiproxy

:alarm_clock: :fire: A TCP proxy to simulate network and system conditions for chaos and resiliency testing
https://github.com/shopify/toxiproxy
MIT License
10.82k stars 449 forks source link

Client cannot connect to proxy even if upstream is down #265

Open ElasticCoder opened 4 years ago

ElasticCoder commented 4 years ago

I am able to connect my client to the proxy even if the upstream server socket is not accepting connections. This means I cannot test all my use cases (e.g. server is absent) because the proxy will accept the connection on behalf of the upstream. When I go to send data it errors, but I would rather the socket is not accepted if upstream is down.

An alternative would be if the upstream rule is disabled then the proxy does not accept connections for that rule.

Behaving in this manner would change the code in which the server accepts connections. During the acceptance, the server would either:

  1. attempt a connection to upstream and refuse the client if that server could not be established, or
  2. verify the rules and if enabled was false it would reject the connection
miry commented 3 years ago

@ElasticCoder I would like to understand the test scenario for this case. Pls correct me if I understand correctly?

  1. Run Upstream application and listen for port 8080
  2. Run Toxiproxy server
  3. Add a proxy to forward packets from port 8081 to 8080
  4. Terminate upstream application
  5. Open a TCP connection to 8081 would return NO port available: port 8081: Connection refused
miry commented 3 years ago

Currently, it is possible to simulate a closed port behavior with toggle feature.

$ toxiproxy-cli create -l 0.0.0.0:20000 -u google.com:443 google_https

$ curl localhost:23232
curl: (7) Failed to connect to localhost port 23232: Connection refused
$ curl localhost:20000
curl: (52) Empty reply from server

$ toxiproxy-cli tog google_https

$ curl localhost:20000
curl: (7) Failed to connect to localhost port 20000: Connection refused
miry commented 3 years ago

Idea how to toggle automatically, it is when the Upstream gracefully shutdown the connection, then server should switch stated to Disabled. But it would require user to toggle back in case upstream restored.