winrm - fix reducing 'Read timed out' error (#78869)

* winrm - fix reducing 'Read timed out' error

This fix reduces the exceptiopn 'Read timed out. (read timeout=nnn)' occurring seemingly randomly and
unpredictable on some networks (which have long latency and/or many hops or other problems). The fix
ensures that the involved timeout is set to a value so this issue is reduced.

* Add changelog fragment

Co-authored-by: Jordan Borean <jborean93@gmail.com>
pull/78804/head
Oskar Ahner 2 years ago committed by GitHub
parent bc274f57f7
commit 3515b3c5fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- winrm - Increase the read timeout to 10 seconds later than the operation timeout reducing the chances of a false read timeout

@ -128,8 +128,29 @@ DOCUMENTATION = """
type: str
connection_timeout:
description:
- Sets the operation and read timeout settings for the WinRM
- Despite its name, sets both the 'operation' and 'read' timeout settings for the WinRM
connection.
- The operation timeout belongs to the WS-Man layer and runs on the winRM-service on the
managed windows host.
- The read timeout belongs to the underlying python Request call (http-layer) and runs
on the ansible controller.
- The operation timeout sets the WS-Man 'Operation timeout' that runs on the managed
windows host. The operation timeout specifies how long a command will run on the
winRM-service before it sends the message 'WinRMOperationTimeoutError' back to the
client. The client (silently) ignores this message and starts a new instance of the
operation timeout, waiting for the command to finish (long running commands).
- The read timeout sets the client HTTP-request timeout and specifies how long the
client (ansible controller) will wait for data from the server to come back over
the HTTP-connection (timeout for waiting for in-between messages from the server).
When this timer expires, an exception will be thrown and the ansible connection
will be terminated with the error message 'Read timed out'
- To avoid the above exception to be thrown, the read timeout will be set to 10
seconds higher than the WS-Man operation timeout, thus make the connection more
robust on networks with long latency and/or many hops between server and client
network wise.
- Setting the difference bewteen the operation and the read timeout to 10 seconds
alligns it to the defaults used in the winrm-module and the PSRP-module which also
uses 10 seconds (30 seconds for read timeout and 20 seconds for operation timeout)
- Corresponds to the C(operation_timeout_sec) and
C(read_timeout_sec) args in pywinrm so avoid setting these vars
with this one.
@ -443,7 +464,7 @@ class Connection(ConnectionBase):
winrm_kwargs = self._winrm_kwargs.copy()
if self._winrm_connection_timeout:
winrm_kwargs['operation_timeout_sec'] = self._winrm_connection_timeout
winrm_kwargs['read_timeout_sec'] = self._winrm_connection_timeout + 1
winrm_kwargs['read_timeout_sec'] = self._winrm_connection_timeout + 10
protocol = Protocol(endpoint, transport=transport, **winrm_kwargs)
# open the shell from connect so we know we're able to talk to the server

Loading…
Cancel
Save