Skip to content

Fix Ping check on non-English Windows by decoding with the OEM code page - #3092

Open
ddog-nasirthomas wants to merge 7 commits into
masterfrom
ping-decode-fix
Open

Fix Ping check on non-English Windows by decoding with the OEM code page#3092
ddog-nasirthomas wants to merge 7 commits into
masterfrom
ping-decode-fix

Conversation

@ddog-nasirthomas

@ddog-nasirthomas ddog-nasirthomas commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes the ping check crashing on non-English Windows. On Windows the check now runs ping via subprocess.run and decodes its output with the OEM code page (decode("oem", errors="replace")) instead of going through get_subprocess_output, which hardcodes a UTF-8 decode. The chcp 65001 approach from 1.0.3 is removed.

Motivation

1.0.3 tried to fix this by switching the console to UTF-8 (chcp 65001), but that turned out not to change the encoding ping actually uses , so a customer on German Windows still hit the same crash ('utf-8' codec can't decode byte 0x81) after updating.

Review checklist

  • PR has a meaningful title or PR has the no-changelog label attached
  • Feature or bugfix has tests
  • Git history is clean
  • If PR impacts documentation, docs team has been notified or an issue has been opened on the documentation repo
  • If this PR includes a log pipeline, please add a description describing the remappers and processors.

Additional Notes

The code fix was not able to be tested on a non-English windows host but a customer tested a similar decode-based fix on their own German Windows host and confirmed it resolves the crash.

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Aug 4, 2026

Copy link
Copy Markdown

Code Coverage

🎯 Code Coverage (details)
Patch Coverage: 96.15%
Overall Coverage: 92.96% (+7.81%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 485b1ae | Docs | Datadog PR Page | Give us feedback!

@ddog-nasirthomas
ddog-nasirthomas marked this pull request as ready for review August 4, 2026 16:55
@ddog-nasirthomas ddog-nasirthomas mentioned this pull request Aug 5, 2026
5 tasks
Comment thread ping/datadog_checks/ping/ping.py Outdated
Comment thread ping/datadog_checks/ping/ping.py Outdated

return lines

def _exec_ping_windows(self, command): # pragma: nocover

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.

This method is the entire fix for a bug that has already escaped once (the 1.0.3 chcp 65001 attempt), yet it's # pragma: nocover with no tests, and test-all-windows.yml is jobs: {} — nothing in CI exercises this path. The "oem" codec itself can't be tested off Windows (codecs.lookup("oem") raises LookupError), but the branching logic (empty-output raise, retcode/err propagation) can be, if the codec is injectable so a test can substitute a real single-byte codec like cp850 and feed it the exact 0x81 byte from the reported crash. Worth confirming in the PR description too: was this validated against a real non-English Windows host? GetOEMCP() can diverge from GetConsoleOutputCP() — the same class of encoding-API mismatch that made the 1.0.3 fix ineffective.

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.

The customer tested a similar fix on their own machine. It was a similar decode-based fix on their own German Windows host and confirmed it resolves the crash. Their change is slightly different, but it is a similar approach decoding ping's output.

I'll update the PR description since I wasn't able to verify this exact fix on a non-English Windows host, but if needed we could possibly give the customer the file to test out. I could also possibly get a sandbox of this up but I think I would need an non-english EC2 instance or an Azure vm

Comment thread ping/datadog_checks/ping/ping.py Outdated
Comment thread ping/CHANGELOG.md Outdated
Comment thread ping/CHANGELOG.md
@ddog-nasirthomas
ddog-nasirthomas requested a review from a team as a code owner August 5, 2026 19:43
@domalessi domalessi self-assigned this Aug 5, 2026
Comment thread ping/datadog_checks/ping/ping.py Outdated
Comment thread ping/tests/test_ping.py Outdated
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.

3 participants