Skip to content

Commit

Permalink
Add command-line argument --timeout, to configure network timeout
Browse files Browse the repository at this point in the history
The default connect timeout is five seconds now.
  • Loading branch information
amotl committed Jan 17, 2024
1 parent 4933513 commit dd27de1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Changes for crash

Unreleased
==========

- Added command-line argument ``--timeout``, to configure network timeout
values in seconds. The default connect timeout is five seconds now,
the default read timeout is infinite.

2024/01/12 0.30.2
=================
Expand Down
21 changes: 21 additions & 0 deletions crate/crash/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def _conf_or_default(key, value):
parser.add_argument('--hosts', type=str, nargs='*',
default=_conf_or_default('hosts', ['localhost:4200']),
help='connect to HOSTS.', metavar='HOSTS')
parser.add_argument('--timeout', type=str, metavar='TIMEOUT',
help='Configure (connect, read) network timeout values different than (5, None) seconds.'
'Obtains either a scalar int or float value used as connect timeout,'
'or a tuple of connect- vs. read-timeout, separated by a comma.', default="5")
parser.add_argument(
'--verify-ssl',
choices=(True, False),
Expand Down Expand Up @@ -620,6 +624,23 @@ def save_and_exit():

def _create_shell(crate_hosts, error_trace, output_writer, is_tty, args,
timeout=None, password=None):

# Explicit "timeout" function argument takes precedence.
if timeout is not None:
if isinstance(timeout, tuple):
connect_timeout, read_timeout = timeout[0], timeout[1]
timeout = urllib3.Timeout(connect=float(connect_timeout), read=float(read_timeout))
else:
timeout = urllib3.Timeout(connect=float(timeout), read=None)

# Probe `--timeout`` command line argument second.
elif args.timeout is not None:
if "," in args.timeout:
connect_timeout, read_timeout = args.timeout.split(",")
timeout = urllib3.Timeout(connect=float(connect_timeout), read=float(read_timeout))
else:
timeout = urllib3.Timeout(connect=float(args.timeout), read=None)

return CrateShell(crate_hosts,
error_trace=error_trace,
output_writer=output_writer,
Expand Down
11 changes: 11 additions & 0 deletions docs/run.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ The ``crash`` executable supports multiple command-line options:
| | command will succeed if at least one |
| | connection is successful. |
+-------------------------------+----------------------------------------------+
| ``--timeout <TIMEOUT>`` | Configure (connect, read) network timeout |
| | values, in seconds. |
| | |
| | Use a single value to configure the connect |
| | timeout, or use a tuple separated by comma |
| | to configure both connect- and read-timeout. |
| | |
| | The default configuration is (5, None), |
| | configuring a connect timeout of five |
| | seconds with infinite read timeout. |
+-------------------------------+----------------------------------------------+
| ``--history <FILENAME>`` | Use ``<FILENAME>`` as a history file. |
| | |
| | Defaults to the ``crash_history`` file in |
Expand Down

0 comments on commit dd27de1

Please sign in to comment.