← Back to Pull requests

fix: Handle healthcheck log corruption gracefully #28803

Closed
unknown closed this pull request without merging on Jun 29, 2026 13:25 UTC
View on GitHub
unknown unknown commented on May 27, 2026 16:34 UTC
Author

The healthcheck log could be corrupted if the
podman heathcheck process was interrupted mid-write leading to Podman crashing when trying to read it.

Steps to reproduce

# Run a container with a health check.
TMPDIR=$(mktemp -d)
podman run -d --name hc-test \
  --health-cmd "true" \
  --health-interval 1s \
  --health-log-destination "$TMPDIR" \
  alpine sleep infinity

# Run a health check.
podman healthcheck run hc-test

# Corrupt the log.
CID=$(podman inspect --format '{{.Id}}' hc-test)
echo "{invalid json{" > $TMPDIR/${CID}-healthcheck.log

# The podman healthcheck command fails.
podman healthcheck run hc-test 
# so does podman ps
podman ps

Output:

➜  podman git:(main) ✗ podman ps
Error: unable to get healthcheck log for 405cdfae215c478036f7f6cc7eed08fb866076654995fc70e14ec59c08164197: failed to unmarshal existing healthcheck results in /tmp/tmp.OvthY1k4nP/405cdfae215c478036f7f6cc7eed08fb866076654995fc70e14ec59c08164197-healthcheck.log: define.HealthCheckResults.ReadString: expects " or n, but found i, error found in #2 byte of ...|{invalid jso|..., bigger context ...|{invalid json{
|...

➜  podman git:(main) ✗ podman healthcheck run hc-test

Error: unable to update health check log /tmp/tmp.OvthY1k4nP/405cdfae215c478036f7f6cc7eed08fb866076654995fc70e14ec59c08164197-healthcheck.log for 405cdfae215c478036f7f6cc7eed08fb866076654995fc70e14ec59c08164197: failed to unmarshal existing healthcheck results in /tmp/tmp.OvthY1k4nP/405cdfae215c478036f7f6cc7eed08fb866076654995fc70e14ec59c08164197-healthcheck.log: define.HealthCheckResults.ReadString: expects " or n, but found i, error found in #2 byte of ...|{invalid jso|..., bigger context ...|{invalid json{

  • Alternatively, it can be reproduced by killing the health check command when it writes to the log. I couldn't get "lucky" with this way, but it should be achievable with creating many systemd units like this script does:

  • #!/usr/bin/python3
    for x in range(50):
      with open(f'/etc/containers/systemd/marshall-{x}.container', 'w') as f:
        f.write(f'''
    [Unit]
    Description=The marshall container {x}
    After=local-fs.target
    [Container]
    Image=registry.access.redhat.com/ubi9-minimal:latest
    Exec=sleep infinity
    HealthCmd=printf '%%01000d' 0
    HealthInterval=1s
    PodmanArgs=--health-max-log-size 0 --health-max-log-count 100
    [Install]
    WantedBy=multi-user.target default.target
    ''')
    

    Running them:

    python create-quadlets.py
    systemctl daemon-reload
    systemctl start marshall-{0..49}
    

    and trying to kill the healtcheck repeatedly until it corrupts the log:
    pkill -9 -f "podman.*healthcheck"
    

    Fix


  • Uses ioutils.AtomicWriteFile to write the health check logs to handle atomic writes with tmpfiles/renames and flushing.

  • It also changes the behavior when reading a corrupted log file in readFromFileHealthCheckLog and instead of a hard error, it logs a warning and continues with an empty log. The corrupted one gets overwritten on a next write. The error could be propagated in readFromFileHealthCheckLog and handled by callers, but this change is localized to a single place instead of multiple callers.

  • Testing: it adds a new system test that intentionally corrupts the log file and checks that Podman recovers (fails with the main version ).
  • Fixes: https://redhat.atlassian.net/browse/RHEL-178222

    Checklist

    Ensure you have completed the following checklist for your pull request to be reviewed:
    <!-- Use [x] to mark as done, or click the checkbox after opening PR -->

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by signing all

  • commits. (git commit -s). (If needed, use git commit -s --amend). The author email must match
    the sign-off email address. See CONTRIBUTING.md
    for more information.
  • Referenced issues using Fixes: #00000 in commit message (if applicable)

  • Tests have been added/updated (or no tests are needed)

  • Documentation has been updated (or no documentation changes are needed)

  • All commits pass make validatepr (format/lint checks)

  • Release note entered in the section below (or None if no user-facing changes)
  • Does this PR introduce a user-facing change?


    None. Unless ignoring and overwriting the corrupted log while logging a warning instead of failing is a user-facing change?

    <!--
    Write None if there are no user-facing changes, otherwise enter your release note below.
    Include "action required" if users need to take action when upgrading.
    -->

    ``release-note

    ``

    Diff: 629 lines (+471 / -158) across 7 files Reviewer: simek-m Review duration: 47331m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 629 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.386
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #28803"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.3% (MEDIUM) · Higher = larger blast radius
    50.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.9% · Safe to merge
    19.9%