diff options
author | Jordan Borean <jborean93@gmail.com> | 2021-06-14 23:54:39 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-14 08:54:39 -0500 |
commit | c6d647a8f0874ec12f3d5cb53e02ec4d917cf78a (patch) | |
tree | 705aa50179e0f70ba4728b201419d7d3668b4c9f | |
parent | 8aa850e3573e48c9a2f12aef84e8a3a6f5ba4847 (diff) | |
download | ansible-c6d647a8f0874ec12f3d5cb53e02ec4d917cf78a.tar.gz |
psrp - Fix reset connection on failed scenarios (#74967) (#74983)
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit cf3a304ce1711ed9a19549fbf58c004acd47c06a)
-rw-r--r-- | changelogs/fragments/psrp-reset.yml | 3 | ||||
-rw-r--r-- | lib/ansible/plugins/connection/psrp.py | 9 |
2 files changed, 12 insertions, 0 deletions
diff --git a/changelogs/fragments/psrp-reset.yml b/changelogs/fragments/psrp-reset.yml new file mode 100644 index 0000000000..a9af487d9e --- /dev/null +++ b/changelogs/fragments/psrp-reset.yml @@ -0,0 +1,3 @@ +bugfixes: +- psrp - Fix error when resetting a connection that was initialised but not connected - (https://github.com/ansible/ansible/issues/74092). +- psrp - Try to clean up any server-side resources when resetting a connection. diff --git a/lib/ansible/plugins/connection/psrp.py b/lib/ansible/plugins/connection/psrp.py index f03eb8782c..b73f796b31 100644 --- a/lib/ansible/plugins/connection/psrp.py +++ b/lib/ansible/plugins/connection/psrp.py @@ -408,7 +408,16 @@ class Connection(ConnectionBase): def reset(self): if not self._connected: + self.runspace = None return + + # Try out best to ensure the runspace is closed to free up server side resources + try: + self.close() + except Exception as e: + # There's a good chance the connection was already closed so just log the error and move on + display.debug("PSRP reset - failed to closed runspace: %s" % to_text(e)) + display.vvvvv("PSRP: Reset Connection", host=self._psrp_host) self.runspace = None self._connect() |