Fix Ping check on non-English Windows by decoding with the OEM code page - #3092
Fix Ping check on non-English Windows by decoding with the OEM code page#3092ddog-nasirthomas wants to merge 7 commits into
Conversation
|
🎯 Code Coverage (details) 🔗 Commit SHA: 485b1ae | Docs | Datadog PR Page | Give us feedback! |
|
|
||
| return lines | ||
|
|
||
| def _exec_ping_windows(self, command): # pragma: nocover |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
What does this PR do?
Fixes the
pingcheck crashing on non-English Windows. On Windows the check now runspingviasubprocess.runand decodes its output with the OEM code page (decode("oem", errors="replace")) instead of going throughget_subprocess_output, which hardcodes a UTF-8 decode. Thechcp 65001approach 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
no-changeloglabel attachedAdditional 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.