-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runspacepool fails to execute commands after a read timeout #21
Comments
I need to test this out to find out what is actually happening but from reading the code if you are catching the error you should still be able to continue using the runspace pool and other pipelines as the runspace will only close when you exit the One thing to note, the timeout value for |
in the normal script I used the default parameters of the wsman object. I eventually managed to prevent it from occuring by adding sleep(0.1) between the poll_invoke() and the begin_invoke(). probably sending multiple messages at once can cause the remote host to get stuck and not respond in time to all of them. on another note, is there any way i can get the process id of the wsmprovhost.exe that is created on the remote host? I want to be sure that this process is closed no matter what error occurs, and this was an example to an error that prevents the remote process from closing. I saw the runspace pool has a shellId but I can't figure out how to get the pid by that. I also dont want to kill all wsmprovhost processes since they can break other things on the remote host. thanks again |
Thanks for the info, I think I just need to dig into it and try and replicate it myself.
You can run add |
The issue is still actual. For me with Wireshark it's looks like that after timeout the library get 401 answer from winrm, tries to authenticate again and receive 400 error with no reason. Maybe some negotiation protocol error? |
Hi, looks like the issue is still happening. I'm writing a tool which keeps RunspacePool open and runs PowerShell scripts periodically (every few minutes). What I noticed, RunspacePool becomes Disconnected on Windows after a few minutes:
The it becomes Disconnected after ~2 minutes:
And after that, any subsequent invocations on RunspacePool fail with 400 bad request:
I tried to work-around it with |
Is there a way to keep a RunspacePool Connected? Seems like |
@relgames Were you able to workaround this issue where after sometime the Sunspace tool fails with 400 bad error exception? |
@yajatns yes, added a custom logic to detect such state and open a new shell, and kill the old one: def __reconnect(self):
# WSMan connections go into Disconnected state after few minutes.
# There is no way at this moment to reconnect, doing so results in HTTP 400 Bad Request
# https://github.com/jborean93/pypsrp/issues/21
# A workaround is to connect a new RunspacePool and kill the previously hanging session
old_shell_id = self.session.shell.id
try:
logger.debug("Trying to reconnect to host %s", self.host)
self.session = self.create_session(self.host, self.username, self.password)
except (WinRMTransportError, WSManFaultError) as e:
logger.error("Could not reconnect to host %s: %s", self.host, e.message)
raise e
try:
self.__kill_shell(old_shell_id)
except (WinRMTransportError, WSManFaultError) as e:
logger.error("Could not kill old shell %s on host %s: %s", old_shell_id, self.host, e.message)
def __kill_shell(self, shell_id):
logger.debug("Killing Shell %s on host %s", shell_id, self.host)
self.run_scriptblock(
"Remove-WSManInstance -ConnectionURI 'http://localhost:5985/wsman' shell @{ShellId='%s'}" % shell_id) |
I've been hitting this issue off and on for a while and I've implemented the "kill shell" workaround which sometimes works but can still fail when you try to recreate the connection (Bad HTTP response returned from the server. Code: 400, Content:'') I am currently using 0.8.1, has anyone tried with the 1.0.0 betas? On that point, is the 1.0.0 ever going to be released? Its been two years since b1 (according to the CHANGELOG) and I am somewhat worried this project is no longer being maintained? Also there is https://github.com/diyan/pywinrm which @jborean93 is contributing to ... is that the new hotness? I tried using that for some scripting tasks but it failed with "The command line is too long" (its quite a big PS script but not that large ...) |
|
Glad to hear that psrp is alive and well and I fully understand the lack of time! Thanks for the info |
I have a runspacepool in which I create multiple powershell commands. I invoke them asynchronously until they complete and parse their outputs. the problem is that if one of the commands get a timeout error, which can be a ReadTimeout, ConnectTimeout etc, it causes the runspacepool to fail, not able to execute more commands, and also unables to close (throws HTTP error 400 in both cases).
this causes 2 issues:
example:
I added a short read_timeout to reproduce the error, but this happened to me with the default parameter. the code will fail when trying to exit the "with RunspacePool" clause
(if you unquote the comments inside the exception, it will show an attempt to run a new PowerShell in the runspacepool after getting a readTimeout, which also fails)
The text was updated successfully, but these errors were encountered: