Skip to content

Draining and health

Dave Cuza edited this page Oct 4, 2026 · 4 revisions

Two questions decide every step of a bounce: is a new replica healthy enough to replace an old one, and how is an old replica taken out of service without cutting requests. This page covers both.

Health

Envoy's health check (always on)

Every replica in the proxy's list is health-checked by Envoy itself. The parameters are fixed:

Parameter Value
Request GET <x-bouncer.healthcheck.uri> (default /), HTTP/1.1
Port the Service's first port (first ports: entry, else first expose: entry)
Expected status 200–499 with no uri set; 2xx when uri is set
Interval 1s
Timeout 1s
Unhealthy after 2 consecutive failures
Healthy after 1 success
New hosts get no traffic until their first check passes

A Service with several ports has one Envoy cluster per port, each checking the first port; Bouncer counts a replica as healthy only when it is healthy in every cluster.

Envoy keeps checking after the bounce: a replica that starts failing stops receiving traffic within about two seconds, and gets it back after one success.

Docker healthcheck (optional)

The service's own Compose healthcheck: stays on the replicas. When a replica has one:

  • it is added to Envoy's list only once Docker reports it healthy, and a running up takes it off the list again if Docker reports it unhealthy (outside a run, Envoy's own check is what stops traffic to it);
  • it must pass both Docker's check and Envoy's to count as healthy.

Without one, a replica is added to the list as soon as it is running and Envoy's check alone decides. Docker's default interval is 30s, which delays every new replica by up to that long; set interval (or start_interval with start_period) to a few seconds.

min_task_uptime

Default 10s. A new replica is happy once it has been continuously healthy (Docker, if it has a check, and Envoy) for min_task_uptime. Only happy new replicas count towards draining an old one, which protects against a version that passes its first checks and then crashes.

  • The clock is kept by the running up/undo process and restarts whenever the replica stops being healthy. A resumed run starts every clock from zero.
  • It gates draining only. A bounce is done once all N new replicas are healthy and no old ones remain; the last ones do not need to reach min_task_uptime.
  • brutal ignores it.

bounce_health_timeout

Default 300s. Each new replica gets until

deadline = max(container created, start of this run) + bounce_health_timeout

to become healthy. If the deadline passes while it is not healthy, the bounce fails:

  1. every new replica that is not healthy is taken off Envoy's list, stopped and removed (healthy new ones stay);
  2. up (or undo) logs <service>: new replica <replica> never passed GET <path> (expects …) within <timeout> (last answer: …) and exits 1.

Old replicas drain only as new ones become happy, so the old version keeps serving. The deadline counts from the container's creation, not its last start, so a crash-looping replica cannot reset it; and it never ends before start of this run + bounce_health_timeout, so a run that resumes after a kill or a reboot gives every replica a full window.

bounce_health_timeout also sets when an abandoned lock is considered stale: after max(5m, bounce_health_timeout × number of Services), using the largest value across the project's Services. See Operations.

Drain methods

Draining is what happens to an old replica once the bounce method allows it to go (and to surplus replicas when you scale down). Every method starts the same way: the replica is taken off Envoy's list, and Bouncer waits until Envoy confirms it applied the new list, so no new request is routed to the replica before the drain starts. Requests already in flight continue.

drain_method After leaving the list
envoy (default) Wait until the proxy holds no established TCP connection to the replica on any Service port, or delay passes. Then stop.
http Call drain, then poll is_safe_to_kill about once a second until it succeeds or delay passes. Then stop.
noop Stop at once.

"Stop" is docker stop with the container's own stop_signal and stop_grace_period (Docker's default is 10s), then removal. So the longest an old replica can take is the list update, plus delay, plus stop_grace_period.

A replica that is already not running (crashed, or stopped by a reboot without a restart policy) skips the wait and is removed at once. brutal skips the wait for every replica, whatever drain_method says.

envoy

Bouncer reads /proc/net/tcp inside the proxy container (via docker exec) about twice a second and counts ESTABLISHED connections to the replica's IP addresses on the Service's container ports. Zero means every request Envoy forwarded has finished. Long-lived streams (WebSockets, server-sent events, long polls) keep the count above zero until delay; they are then cut when the replica stops, and clients reconnect through the proxy to a new replica. Set delay above your longest normal request.

If reading the connection count fails transiently, Bouncer logs it and keeps waiting until delay.

http

Hooks let the app decide when it is safe to stop, the way PaaSTA's HTTP drain method does.

drain_method: http
drain_method_params:
  delay: 120s
  drain:           { method: POST, path: /admin/drain }
  is_safe_to_kill: { path: /admin/idle, success_codes: [200] }
  stop_draining:   { method: POST, path: /admin/undrain }
  • Requests are sent from inside the proxy container to the replica's container name on the Service's first port, as HTTP/1.1 with Host: <replica container name> and no body. The app does not need to publish anything.
  • Each call has method (default GET), path, and success_codes (default any 2xx).
  • drain is called once. Its status code is not checked; only a connection error matters, and then Bouncer logs http drain of <replica>: … (stopping anyway) and stops the replica.
  • is_safe_to_kill is polled until it returns a success code. If delay passes first, Bouncer logs that the replica was not safe to kill and stops it anyway.
  • drain and is_safe_to_kill are required; stop_draining is optional.

stop_draining undoes a drain that never finished. If a run is killed mid-drain, the next run finds the half-drained replica still running and puts it back on Envoy's list. Just before that, it sends stop_draining to every replica it is about to re-add that was created before the current run started. That set can include replicas that were never drained (for example the first run after the proxy was recreated, or a replica returning from a failing Docker healthcheck), so stop_draining must be idempotent: calling it on a replica that is not draining must be harmless. Errors are logged and ignored.

noop

The replica is taken off the list and stopped immediately. In-flight requests get only the stop_grace_period your app spends shutting down after its stop signal. Use it when the app drains itself on SIGTERM.

delay

drain_method_params.delay (default 60s) bounds the envoy and http waits. It is not a fixed sleep: the wait ends as soon as the connection count is zero or is_safe_to_kill succeeds. noop ignores it.

How long a bounce takes

Roughly, per replacement: image already pulled → container start → Docker healthy (if a healthcheck) → listed → first Envoy check (≤ 1s) → min_task_uptime → drain (≤ delay) → stop (≤ stop_grace_period). crossover with a larger surge overlaps the replacements.

Clone this wiki locally