Skip to content

fix(helm): the frontend keeps serving 10 s after it is marked for deletion - #2350

Merged
lilyshen0722 merged 2 commits into
mainfrom
sre-frontend-prestop
Oct 22, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
sre-frontend-prestop

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Merge after: the Thu 10-22 / Fri 10-23 change slot. This is a draft, held for that slot. Don't press it before then, and it is not part of Tuesday's deploy.

What happened

Today's two Deploy Dev rollouts each had one request hang during the frontend swap. I probed https://commonly.me/v2 every 2 s, with a 5 s client timeout, through both rollouts.

rollout probes non-200 when
1 88 1 (no response in 5 s) the second pod swap, about 4 s after the old pod was told to stop
2 81 1 (no response in 5 s) the second pod swap

The API probes in rollout 2 answered 200 every time; the backend already has a preStop sleep.

Why

  • When a pod is deleted, ingress-nginx drops it from its upstreams only after the endpoint update reaches the controller.
  • The frontend image runs nginx with no preStop. Its stop signal is SIGQUIT (inherited from nginx:alpine, read from both image configs), nginx's graceful quit, which exits as soon as no request is in flight. So the pod is gone, and its address stops answering, before ingress-nginx drops it.
  • A request ingress-nginx sends to that address during the gap waits out its proxy_connect_timeout before trying the next upstream. That timeout is 5 s (read from the controller's live nginx.conf, with proxy_next_upstream error timeout and 3 tries).
  • That matches what the probes saw: a hang of at least 5 s, not a fast 502.

Change

The frontend container gets the backend's preStop (sleep 10), so a terminating pod keeps serving until ingress-nginx has dropped it.

helm template with values.yaml + values-dev.yaml changes only this:

@@ frontend Deployment, container "frontend"
           initialDelaySeconds: 10
           periodSeconds: 5
+        lifecycle:
+          preStop:
+            exec:
+              command: ["/bin/sh", "-c", "sleep 10"]
       nodeSelector:

The template's six-line comment also renders; it is left out above. tests.yml asserts the rendered frontend preStop the same way it already asserts the backend's.

Cost

Each frontend pod takes about 10 s longer to stop. The hostname anti-affinity is required, so a replacement pod likely waits for the old pod to leave its node. That would stretch each swap by about 10 s, all of it on the other replica, which is what maxUnavailable: 1 already allows. Grace stays at the default 30 s; 10 s of sleep plus the nginx stop fits inside it.

Test plan (in the slot, not before)

  1. Probe the web every 1 s with a 5 s timeout through the Deploy Dev run that carries this change.
  2. Then probe through two kubectl rollout restart deploy/frontend runs. That's four pod swaps, each with a server-side preStop.
  3. Pass: 0 non-200 responses across all three rollouts. Also record how long each replacement pod stays Pending, which checks the Cost estimate.
  4. Fail: any hang. The next step would be a longer sleep; a graceful nginx -s quit in the hook would add nothing, because SIGQUIT already is one. That decision waits for the measurement.
  5. Rollback: revert this commit and redeploy. It is a template-only change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MCgCsf3UJRCPRbnNKxsECe

…etion

ingress-nginx drops a terminating pod from its upstreams a moment after the
deletion, while nginx in the frontend image exits at once on SIGTERM. A request
sent in that gap goes to a pod that is gone and waits out ingress-nginx's 5 s
proxy_connect_timeout before it retries. Both rollouts on 2026-10-19 showed
exactly one such 5 s hang, each during the second pod swap. The backend already
has the same 10 s preStop sleep; CI now asserts the frontend's too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MCgCsf3UJRCPRbnNKxsECe

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gate review @ 8a861cd4ec: PASS. It merges in its own Thu 10-22 / Fri 10-23 slot, not before.

What I checked

  • The rendered chart changes only where the PR says. I rendered the dev chart at main and at this head with the CI invocation (helm template commonly-dev … -f values.yaml -f values-dev.yaml). The only difference is the frontend container's lifecycle.preStop block and its comment: 4449 → 4459 lines, nothing else.
  • The hook can run in this image. The frontend's final stage is nginx:alpine. On the live frontend pod, /bin/sh is busybox and command -v sleep gives /bin/sleep. A hook whose binary is missing would fail and leave the gap open, so this was the thing to measure.
  • It matches the backend exactly. The command is the same ["/bin/sh", "-c", "sleep 10"] as the backend container's preStop. The pod sets no terminationGracePeriodSeconds, so the default 30 s easily covers 10 s of hook plus nginx's shutdown.
  • It fits the rollout shape from #2342. With 2 replicas, maxSurge 0 and maxUnavailable 1, the pod being replaced keeps answering for 10 s while ingress-nginx drops it, and the other replica keeps serving. So the change can only shorten a request's wait.
  • There's a reader. The new tests.yml line asserts command[2] == "sleep 10" on the rendered frontend container, the same way the backend's is checked. CI: 14 pass, 2 skipping. The author is Lily (noreply), and the head matches the branch.

Not checked, non-blocking. The comment says nginx "exits at once on SIGTERM". I didn't measure which stop signal this nginx image receives under the cluster runtime. The fix doesn't depend on it: the gap it closes is the one between the pod being marked for deletion and ingress-nginx removing it, which comes before any signal. The proof is your slot test: a 1 s probe through the deploy plus two rollout restart runs, with 0 non-200.

GATE: PASS

The preStop comment said nginx exits at once on SIGTERM. The frontend
image inherits nginx:alpine's StopSignal SIGQUIT (read from both image
configs), and the runtime uses it when the pod spec sets none. SIGQUIT is
nginx's graceful quit, which exits as soon as no request is in flight, so
the race and the fix are unchanged. Comment only; the rendered objects
are identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MCgCsf3UJRCPRbnNKxsECe

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-gate at 523d65dc (previous PASS was at 8a861cd4).

  • The one commit since then (523d65dc, author Lily Shen) changes only the comment above lifecycle in frontend-deployment.yaml, 6 lines for 5. preStop is still ["/bin/sh", "-c", "sleep 10"], and nothing outside YAML comment lines moved.
  • The corrected comment holds: the official nginx images set STOPSIGNAL SIGQUIT, and SIGQUIT is nginx's graceful quit. The conclusion is unchanged either way: nginx is gone before ingress-nginx drops the pod, so the sleep is still the fix.
  • The PR body's Fail line now says the fallback is a longer sleep, not nginx -s quit. That matches the comment.
  • CI at this head: 14 pass, 2 skipping.

Hold for the Thu 10-22 / Fri 10-23 slot, as before.

GATE: PASS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant