Skip to content
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

Raise exception if command timeout is triggered #43078

Merged
merged 6 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 16 additions & 9 deletions bin/ansible-connection
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import os
import signal
import socket
import sys
import time
import traceback
import errno
import json
Expand Down Expand Up @@ -136,22 +137,28 @@ class ConnectionProcess(object):
self.exception = traceback.format_exc()

finally:
# when done, close the connection properly and cleanup
# the socket file so it can be recreated
# allow time for any exception msg send over socket to receive at other end before shutting down
time.sleep(0.1)

# when done, close the connection properly and cleanup the socket file so it can be recreated
self.shutdown()

def connect_timeout(self, signum, frame):
display.display('persistent connection idle timeout triggered, timeout value is %s secs'
% self.connection.get_option('persistent_connect_timeout'), log_only=True)
self.shutdown()
msg = 'persistent connection idle timeout triggered, timeout value is %s secs.\nSee the timeout setting options in the Network Debug and ' \
'Troubleshooting Guide.' % self.connection.get_option('persistent_connect_timeout')
display.display(msg, log_only=True)
raise Exception(msg)

def command_timeout(self, signum, frame):
display.display('command timeout triggered, timeout value is %s secs' % self.connection.get_option('persistent_command_timeout'), log_only=True)
self.shutdown()
msg = 'command timeout triggered, timeout value is %s secs.\nSee the timeout setting options in the Network Debug and Troubleshooting Guide.'\
% self.connection.get_option('persistent_command_timeout')
display.display(msg, log_only=True)
raise Exception(msg)

def handler(self, signum, frame):
display.display('signal handler called with signal %s' % signum, log_only=True)
self.shutdown()
msg = 'signal handler called with signal %s.' % signum
display.display(msg, log_only=True)
raise Exception(msg)

def shutdown(self):
""" Shuts down the local domain socket
Expand Down
9 changes: 4 additions & 5 deletions lib/ansible/module_utils/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,18 @@ def _exec_jsonrpc(self, name, *args, **kwargs):
req = request_builder(name, *args, **kwargs)
reqid = req['id']

troubleshoot = 'https://docs.ansible.com/ansible/latest/network/user_guide/network_debug_troubleshooting.html#category-socket-path-issue'

if not os.path.exists(self.socket_path):
raise ConnectionError('socket_path does not exist or cannot be found. Please check %s' % troubleshoot)
raise ConnectionError('socket_path does not exist or cannot be found.'
'\nSee the socket_path issue catergory in Network Debug and Troubleshooting Guide')

try:
data = json.dumps(req)
out = self.send(data)
response = json.loads(out)

except socket.error as e:
raise ConnectionError('unable to connect to socket. Please check %s' % troubleshoot, err=to_text(e, errors='surrogate_then_replace'),
exception=traceback.format_exc())
raise ConnectionError('unable to connect to socket. See the socket_path issue catergory in Network Debug and Troubleshooting Guide',
err=to_text(e, errors='surrogate_then_replace'), exception=traceback.format_exc())

if response['id'] != reqid:
raise ConnectionError('invalid json-rpc id received')
Expand Down