Skip to content

Conversation

@vyadavmsft
Copy link
Collaborator

When PowerShell commands timeout and are killed, stderr may be empty or contain non-XML content. The _parse_error_message() method was attempting to parse all stderr as XML without validation, causing ElementTree.ParseError.

Changes:

  • Add check for empty/whitespace-only stderr
  • Return raw stderr if it doesn't start with CLIXML header
  • Wrap XML parsing in try-except to handle malformed XML gracefully
  • Return raw stderr (minus CLIXML header) if parsing fails

This prevents crashes when processes are killed due to timeout or produce non-standard error output.

When PowerShell commands timeout and are killed, stderr may be empty or
contain non-XML content. The _parse_error_message() method was attempting
to parse all stderr as XML without validation, causing ElementTree.ParseError.

Changes:
- Add check for empty/whitespace-only stderr
- Return raw stderr if it doesn't start with CLIXML header
- Wrap XML parsing in try-except to handle malformed XML gracefully
- Return raw stderr (minus CLIXML header) if parsing fails

This prevents crashes when processes are killed due to timeout or produce
non-standard error output.
@squirrelsc
Copy link
Member

I looked into similar issues before, and it seems the empty PowerShell output is caused by cached results. You might want to handle unexpected cache behavior—either by skipping the cache altogether or tweaking the PowerShell command to work better with it.

@vyadavmsft
Copy link
Collaborator Author

I looked into similar issues before, and it seems the empty PowerShell output is caused by cached results. You might want to handle unexpected cache behavior—either by skipping the cache altogether or tweaking the PowerShell command to work better with it.

in my case its not a cache issue , The Get-VMSwitch PowerShell command hanging for 10 minutes suggests a Hyper-V infrastructure issue, not a cache issue . it wasn't valid XML because the process was killed mid-execution, The XML parsing crash happened AFTER the timeout - the original problem was the hanging Get-VMSwitch command.

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