Skip to content

fix(shutdown-manager): deliver the shutdown ready response after a long drain - #10186

Closed
sharad-baid-mrsool wants to merge 2 commits into
envoyproxy:mainfrom
sharad-baid-mrsool:fix-shutdown-ready-write-deadline
Closed

sharad-baid-mrsool wants to merge 2 commits into
envoyproxy:mainfrom
sharad-baid-mrsool:fix-shutdown-ready-write-deadline

Conversation

@sharad-baid-mrsool

Copy link
Copy Markdown

What this PR does / why we need it:

The Envoy container's preStop hook is httpGet /shutdown/ready :19002. The handler blocks until the shutdown-manager's own preStop (envoy-gateway envoy shutdown) finishes the drain and writes /tmp/shutdown-ready, which with the default --ready-timeout can take minutes. But the shutdown manager's http.Server has WriteTimeout: 10s. The deadline is set when the request is read, so for any drain longer than 10s the handler's response (200 on readiness, 500 on timeout) can't be written. The connection closes with no response, and the kubelet logs FailedPreStopHook for every proxy pod termination.

The drain itself works. The hook stays blocked for the whole drain, and SIGTERM still reaches Envoy once the ready file exists. So the effect is a misleading event, not lost connections. It is still costly in practice: during an incident it reads exactly like a failed drain. We saw this on every termination with drainTimeout: 300s and long-lived WebSocket connections, on v1.8.4.

This change:

  • extends the write deadline for the /shutdown/ready response only, using http.ResponseController.SetWriteDeadline, to readyTimeout + 5s. The margin covers the final 1s poll interval and the write. /healthz keeps the 10s server timeout.
  • extracts the server construction into newShutdownManagerServer so it can be tested, and makes the write timeout a package variable so the test can shorten it.
  • adds TestShutdownReadyResponseOutlivesWriteTimeout. It runs the real server with a 100ms write timeout and checks that both the 200 (drain completes) and 500 (ready timeout exceeded) responses are delivered. Without the fix both cases fail with EOF, which is what the kubelet reports as the failed hook.

This is the same problem as the closed, never-reviewed draft #10074. That draft raised the server-wide WriteTimeout; this PR scopes the change to the one blocking endpoint.

Which issue(s) this PR fixes:

No existing issue; same problem as #10074.


PR Checklist

  • Authorship & ownership: Coding agents / AI assistants are welcome, but I have reviewed every change, understand how and why it works, can explain and maintain it, and take full responsibility for this PR. I have not submitted generated output I do not understand.
  • DCO: All commits are signed off (git commit -s).
  • API agreed first: N/A: no API changes.
  • Required checks pass: go test ./internal/cmd/envoy/ and golangci-lint (repo config) pass on the changed package locally; full CI pending.
  • Tests added/updated: TestShutdownReadyResponseOutlivesWriteTimeout.
  • Docs: N/A: no user-facing configuration change.
  • Release notes: release-notes/current/bug_fixes/.
  • Generated files committed: N/A: no API, helm chart or module changes.
  • Scope & compatibility: Scoped to the shutdown manager; no behavior change other than the response now being delivered.
  • Codex review
  • Copilot review

🤖 Generated with Claude Code

…ng drain

The Envoy container's preStop hook is an httpGet on /shutdown/ready, which
blocks until the drain writes the ready file. The shutdown manager server has a
10s WriteTimeout, so for any drain longer than that the response can no longer
be written: the kubelet sees the connection close without a response and
reports FailedPreStopHook on every pod termination, even though the drain
completed normally.

Extend the write deadline for the shutdown ready response only, to the ready
timeout plus a small margin. Other endpoints keep the 10s server timeout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: sharad-baid-mrsool <[email protected]>
@netlify

netlify Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cerulean-figolla-1f9435 ready!

Name Link
🔨 Latest commit f4d0322
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/6ac390a4a229ab000865d71b
😎 Deploy Preview https://deploy-preview-10186--cerulean-figolla-1f9435.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: sharad-baid-mrsool <[email protected]>
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