winrm
winrm copied to clipboard
If windows VM network abrupts or resets, the winrm connection breaks and then does not reconnect
Issue: When trying to connect to a windows VM using a go program and fetching list of directories in loop for 5 times
If during this operation, windows VM network disconnects or network service restarts, the connection to windows VM breaks with following error:
Error while running command :unknown error Post "http://74.225.159.106:5985/wsman": net/http: timeout awaiting response headers
And then when retry is tried the connection fails with the following errors
:http response error: 401 - invalid content type
I already tried recreating endpoint and client object again during next retry once the connection fails during timeout but still same error occurs
endpoint config used:
winrm.NewEndpoint("<windows-VM-IP>", 5985, false, false, nil, nil, nil, 300)
winrm config:
Authentication used for winRM Client and Service: Basic Allow unencrypted traffic: true
Code used: // creating a new client object client, err = winrm.NewClient(endpoint, username, password)
loop start stdout, stderr, stdcode, err := client.RunWithString("dir", "") if err != nil { log.Println("Error creating connection and executing command: ", err) if max retry done: return err else: continue } if stdcode != 0 { log.Println("Error: encountered during executing command: ", err) if max retry done: return err else: continue } else { return nil }
return nil