Skip to content

Fix readiness probe for containers without HEALTHCHECK#417

Closed
yonghaoy wants to merge 1 commit into
masterfrom
fix/healthcheck-nil-state
Closed

Fix readiness probe for containers without HEALTHCHECK#417
yonghaoy wants to merge 1 commit into
masterfrom
fix/healthcheck-nil-state

Conversation

@yonghaoy
Copy link
Copy Markdown
Contributor

Summary

  • Fix probe-proxy-readiness.sh to use a Go template conditional ({{if .State.Health}}) instead of relying on docker inspect exit code to detect containers without a HEALTHCHECK
  • This fixes non-SAS apps (jupyter, vscode, etc.) getting stuck in "Starting" state indefinitely

Problem

PR #415 added health check awareness to the readiness probe, but the Go template {{.State.Health.Status}} behaves differently across Docker versions when .State.Health is nil (no HEALTHCHECK configured). Some Docker versions return an empty string with exit code 0, bypassing the || echo "none" fallback. This causes APP_HEALTH="", which matches neither "healthy" nor "none", so the readiness probe fails forever.

Fix

-APP_HEALTH="$(docker inspect --format='{{.State.Health.Status}}' application-server 2>/dev/null || echo "none")"
+APP_HEALTH="$(docker inspect --format='{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' application-server 2>/dev/null || echo "none")"

The Go template conditional handles nil .State.Health directly inside the template, making it work reliably regardless of Docker version.

Test plan

  • Verify non-SAS apps (jupyter, vscode) transition to "Running" state correctly
  • Verify SAS app still waits for healthy status before marking COMPLETE
  • Recreate stuck VMs in vwb-dev-informal-olive-8524 after merge

🤖 Generated with Claude Code

The Go template `{{.State.Health.Status}}` behaves differently across
Docker versions when .State.Health is nil (no HEALTHCHECK configured).
Some versions return an empty string with exit 0, bypassing the
`|| echo "none"` fallback and causing the readiness probe to fail
indefinitely for non-SAS apps (jupyter, vscode, etc.).

Use a Go template conditional to handle nil .State.Health directly,
making the probe work reliably regardless of Docker version.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@yonghaoy yonghaoy requested review from a team as code owners May 20, 2026 16:32
@yonghaoy
Copy link
Copy Markdown
Contributor Author

Closing in favor of #416 which correctly identified the root cause: docker inspect outputs an empty line to stdout before failing on containers without HEALTHCHECK, resulting in APP_HEALTH="\nnone" (leading newline). PR #416's | xargs approach correctly strips this. My Go template conditional fix also works but #416 was first and correct.

@yonghaoy yonghaoy closed this May 20, 2026
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