diff --git a/CHANGES.txt b/CHANGES.txt index 5155a1dc..a85bed7f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 ================= diff --git a/crate/crash/command.py b/crate/crash/command.py index 0d6b6662..4de581ba 100644 --- a/crate/crash/command.py +++ b/crate/crash/command.py @@ -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), @@ -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, diff --git a/docs/run.rst b/docs/run.rst index 2177cd66..a6c99ba5 100644 --- a/docs/run.rst +++ b/docs/run.rst @@ -57,6 +57,17 @@ The ``crash`` executable supports multiple command-line options: | | command will succeed if at least one | | | connection is successful. | +-------------------------------+----------------------------------------------+ +| ``--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 `` | Use ```` as a history file. | | | | | | Defaults to the ``crash_history`` file in |