Skip to content

fix: resolve broken pipe and JSONDecodeError in poll-validation.sh#511

Merged
aavinash-nr merged 1 commit into
newrelic:masterfrom
aavinash-nr:fix/poll-validation-broken-pipe
Jun 24, 2026
Merged

fix: resolve broken pipe and JSONDecodeError in poll-validation.sh#511
aavinash-nr merged 1 commit into
newrelic:masterfrom
aavinash-nr:fix/poll-validation-broken-pipe

Conversation

@aavinash-nr

@aavinash-nr aavinash-nr commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What

Fixes a silent crash in poll-validation.sh that happens when layer validation fails. The script was supposed to print which specific functions failed and why, but instead it threw a broken pipe + JSONDecodeError, so the failure detail was never shown.

Why it broke

The original code piped $result into python3 while also using a heredoc for the script body — both trying to own Python's stdin at the same time. Bash gives the heredoc priority, leaving the pipe unread → broken pipe. Python then reads an empty stdin → JSONDecodeError.

# broken
echo "$result" | python3 - <<'PYEOF'
import json, sys
d = json.load(sys.stdin)  # sys.stdin is empty, crash
PYEOF

Fix

Write the result to a temp file and read from there, so there's no stdin conflict.

printf '%s' "$result" > /tmp/val_result.json
python3 <<'PYEOF'
import json
with open('/tmp/val_result.json') as f:
    d = json.load(f)
PYEOF

Test Plan

  • Validation failure run: per-function failure detail prints correctly, no broken pipe error
  • Validation pass run: no regression in the success path

🤖 Generated with Claude Code

When validation fails, the failure-detail printer used:
  echo "$result" | python3 - <<'PYEOF'

Bash gives the heredoc ownership of python3's stdin, so the pipe
from echo has no reader (Broken pipe). Inside Python, sys.stdin is
already consumed by the heredoc script, so json.load(sys.stdin)
receives an empty string and raises JSONDecodeError.

Fix: write $result to a temp file and read it from there, removing
the pipe/heredoc stdin conflict entirely.

@Sashwatdas123 Sashwatdas123 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@aavinash-nr aavinash-nr merged commit e4f8a50 into newrelic:master Jun 24, 2026
2 checks passed
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.

2 participants