Skip to content

Commit f5a2a70

Browse files
committed
Add command-line argument --timeout, to configure network timeout
The default connect timeout is five seconds now. The default read timeout is "infinite".
1 parent 14b8d9f commit f5a2a70

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

CHANGES.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ Changes for crash
44

55
Unreleased
66
==========
7-
7+
- Added command-line argument ``--timeout``, to configure network timeout
8+
values in seconds. The default connect timeout is five seconds now,
9+
the default read timeout is the default setting of the ``socket`` module,
10+
which in turn is "infinite" by default.
811

912
2024/01/12 0.30.2
1013
=================

crate/crash/command.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ def _conf_or_default(key, value):
139139
parser.add_argument('--hosts', type=str, nargs='*',
140140
default=_conf_or_default('hosts', ['localhost:4200']),
141141
help='connect to HOSTS.', metavar='HOSTS')
142+
parser.add_argument('--timeout', type=str, metavar='TIMEOUT',
143+
help='Configure "connect,read" network timeout values different than "5,infinite" seconds.'
144+
'Obtains either a scalar integer or float value used as connect timeout,'
145+
'or a tuple of connect- vs. read-timeout, separated by a comma.', default="5")
142146
parser.add_argument(
143147
'--verify-ssl',
144148
choices=(True, False),
@@ -620,6 +624,23 @@ def save_and_exit():
620624

621625
def _create_shell(crate_hosts, error_trace, output_writer, is_tty, args,
622626
timeout=None, password=None):
627+
628+
# Explicit "timeout" function argument takes precedence.
629+
if timeout is not None:
630+
if isinstance(timeout, tuple):
631+
connect_timeout, read_timeout = timeout[0], timeout[1]
632+
timeout = urllib3.Timeout(connect=float(connect_timeout), read=float(read_timeout))
633+
else:
634+
timeout = urllib3.Timeout(connect=float(timeout), read=None)
635+
636+
# Probe `--timeout`` command line argument second.
637+
elif args.timeout is not None:
638+
if "," in args.timeout:
639+
connect_timeout, read_timeout = args.timeout.split(",")
640+
timeout = urllib3.Timeout(connect=float(connect_timeout), read=float(read_timeout))
641+
else:
642+
timeout = urllib3.Timeout(connect=float(args.timeout), read=None)
643+
623644
return CrateShell(crate_hosts,
624645
error_trace=error_trace,
625646
output_writer=output_writer,

docs/run.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ The ``crash`` executable supports multiple command-line options:
5757
| | command will succeed if at least one |
5858
| | connection is successful. |
5959
+-------------------------------+----------------------------------------------+
60+
| ``--timeout <TIMEOUT>`` | Configure (connect, read) network timeout |
61+
| | values, in seconds. |
62+
| | |
63+
| | Use a single value to configure the connect |
64+
| | timeout, or use a tuple separated by comma |
65+
| | to configure both connect- and read-timeout. |
66+
| | |
67+
| | The default configuration is "5,infinite", |
68+
| | configuring a connect timeout of five |
69+
| | seconds with infinite read timeout. |
70+
+-------------------------------+----------------------------------------------+
6071
| ``--history <FILENAME>`` | Use ``<FILENAME>`` as a history file. |
6172
| | |
6273
| | Defaults to the ``crash_history`` file in |

0 commit comments

Comments
 (0)