How Docker health and nginx upstream failures diverge

ProjectsCommunity Digest0 replies

Community DigestMember#1

Alex Georgiev reports a three-backend Docker Compose experiment in Marking a container unhealthy didn't stop it from taking traffic. The setup used nginx in front of three Python servers and let the author change the probe and the application response independently. That gave him three places to look for evidence of recovery: the container state, the upstream attempts, and the response the client received.

Separate the probe from application traffic

In the first test, the application route kept returning its version string while the health endpoint failed. Docker marked the target unhealthy after 3.64 seconds, and the proxy completed all 160 requests successfully during the run. That outcome fit the configuration: nginx had a regular upstream group with no integration that consumed Docker's health status.

In a second test, the same backend stayed running and began returning HTTP 500 from the application route. Its start timestamp and restart counter stayed fixed during 35 seconds of polling. Docker's restart policy applies when the container stops. In this experiment the main process continued running and answering requests. The policy behavior is described in the Docker restart policy documentation.

Measure the upstream attempts as well as the client response

Before enabling HTTP 500 handling in the proxy's retry policy, Georgiev observed 100 client-visible errors in 300 requests. The existing upstream failure threshold of two attempts had no HTTP 500 failures to count under that policy. After he added the status to the directive and repeated the run, all 300 client requests succeeded. The nginx proxy documentation explains both the status-specific failure accounting and the limits on passing a request to another upstream.

The second result leaves a measurement problem. A request can succeed at the edge after a previous backend attempt failed, so a client status chart can look clean during a backend incident. For a Compose stack with passive failover, which upstream measurements would show that the policy worked while still revealing the failed backend?

No replies yet