-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add command-line argument --timeout
, to configure network timeout values
#421
Conversation
dedb274
to
dd27de1
Compare
dd27de1
to
f5a2a70
Compare
9274ca8
to
a5b3335
Compare
f5a2a70
to
44225d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx, left some comments/questions
crate/crash/command.py
Outdated
@@ -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,infinite" seconds.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just double checking, infinite
is a valid value that is parsed by urllib3.Timout()
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for asking. "infinite"
isn't a valid value, it is just a surrogate. When obtaining Python's None
symbol, the timeout will be infinite. Currently, there is no way to obtain this value from a text representation from the command line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a suggestion how to improve code or docs around this topic, either by actually implementing inf(inite)
as a surrogate keyword representing None
, or, alternatively, by improving the documentation / help / guidance texts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say None
is fine, I like it, since None
does seem to be specially valuable here, and it actually reads nice as ìf timeout is None
-> no timeout, hence 'infinite'.
Otherwise sentinel object but imo it's too much
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I also think it is fine from the perspective of the Python API, and I agree that a sentinel object is not needed as a surrogate for None
here.
In this case, I think it would be more about discussing the need to find a corresponding textual representation to make the "infinite" surrogate be obtainable from the command line via --timeout=
. Would you prefer that the literal "None"
would be translated to None
, or would you prefer that the literal "inf"
or "infinite"
would be translated to None
?
Without implementing that, I think there would currently be no possibility to configure, for example, an infinite connect timeout. We would need to check / validate what --timeout=,42
does, and eventually shape it a bit more to converge this merely undefined behaviour into something with a more sensible semantic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imho, we should give the chance to the user to configure the default "infinite" value, if needed,
so I'd go with None
(case insensitive though, so that none, NONE, NoNE, etc. is all the same)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also use 0
or -1
on the cmd line to make it translate internally to infinite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. 0 or -1 are commonly used to set no-timeout/infinite. +1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. The patch has been amended to implement your suggestion. Now, -1
can be used as a surrogate value to represent None
, which means "infinite timeout".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch has been significantly amended, so I am humbly asking for another review. Thank you again.
44225d3
to
1a8da52
Compare
1a8da52
to
eb20aa2
Compare
eb20aa2
to
1d561eb
Compare
f09065a
to
6f58fac
Compare
crate/crash/command.py
Outdated
elif len(timeouts) == 2: | ||
connect_timeout, read_timeout = timeouts[0], timeouts[1] | ||
else: | ||
raise ValueError(f"Decoding timeout values failed: {timeout}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise ValueError(f"Decoding timeout values failed: {timeout}") | |
raise ValueError(f"Cannot decode timeout {timeout}, expected format `<connect_sec>,<read_sec>`") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I've adjust this error message, and also aligned the other one for the TypeError
a few lines above.
The default connect timeout is five seconds now. The default read timeout is "infinite".
6f58fac
to
365be94
Compare
About
Coming from GH-370, this patch introduces the
--timeout
command-line argument to specify the (connect, read) timeout values. The default connect timeout is five seconds now, the default read timeout is infinite.Backlog
urllib3.Timeout
instances for defining timeout values crate-python#603.