winrm icon indicating copy to clipboard operation
winrm copied to clipboard

Executing a winrm command that shuts down the machine

Open sneal opened this issue 1 year ago • 2 comments

It appears a recent commit broke some assumptions in stembuild that executes a sysprep shutdown command that never finishes.

Is there a recommended method of executing a winrm command which may be interrupted by a shutdown? Previously we were expecting an error like winrm connection event: unknown error Post "http://10.220.41.242:5985/wsman": read tcp 10.220.41.9:34002->10.220.41.242:5985: read: connection timed out and just continuing when that happened. Now the winrm command never finishes and winrm command fetchOutput goes into an infinite loop waiting for the machine to come back up which will never happen.

sneal avatar Feb 21 '24 02:02 sneal

Indeed, we used to return early when timeouts were happening, now we try harder because it can happen the remote host just times out for long commands. Beside making that behavior optional, I don't see exactly how to fix the problem, because both behavior are antinomic. I'll think about it, but feel free to propose a fix.

masterzen avatar Feb 26 '24 19:02 masterzen

I'll have to think on this as well. I'll have to look a little deeper as this may already exist, but I'd expect there to be some sort of configurable command timeout error that would eventually be returned to the caller vs waiting forever.

In this specific case we expect the connection to break - signaling command completion. So the behavior we really want is to execute the command and block until the machine stops responding. The command timeout seems like a good backstop, but I think ultimately in this case stembuild needs to kick off the winrm command one one goroutine and then in another poll for the machine to be shutdown (ideally querying the IaaS).

sneal avatar Feb 28 '24 01:02 sneal