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

Add command-line argument --timeout, to configure network timeout values #421

Merged
merged 1 commit into from
Jan 29, 2024

Conversation

amotl
Copy link
Member

@amotl amotl commented Jan 12, 2024

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

CHANGES.txt Outdated Show resolved Hide resolved
@amotl amotl changed the base branch from master to amo/fix-version-compares January 17, 2024 23:15
@amotl amotl force-pushed the amo/fix-version-compares branch 2 times, most recently from 9274ca8 to a5b3335 Compare January 18, 2024 18:23
@amotl amotl marked this pull request as ready for review January 18, 2024 18:32
Copy link
Contributor

@matriv matriv left a 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 Show resolved Hide resolved
@@ -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.'
Copy link
Contributor

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?

Copy link
Member Author

@amotl amotl Jan 19, 2024

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.

Copy link
Member Author

@amotl amotl Jan 19, 2024

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?

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

Copy link
Member Author

@amotl amotl Jan 19, 2024

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.

Copy link
Contributor

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)

Copy link
Contributor

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.

Copy link
Member

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

Copy link
Member Author

@amotl amotl Jan 24, 2024

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".

Copy link
Member Author

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.

CHANGES.txt Outdated Show resolved Hide resolved
crate/crash/command.py Show resolved Hide resolved
Base automatically changed from amo/fix-version-compares to master January 19, 2024 09:27
@amotl amotl requested a review from matriv January 19, 2024 13:08
@amotl amotl force-pushed the amo/add-timeout branch 3 times, most recently from f09065a to 6f58fac Compare January 24, 2024 17:38
elif len(timeouts) == 2:
connect_timeout, read_timeout = timeouts[0], timeouts[1]
else:
raise ValueError(f"Decoding timeout values failed: {timeout}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise ValueError(f"Decoding timeout values failed: {timeout}")
raise ValueError(f"Cannot decode timeout {timeout}, expected format `<connect_sec>,<read_sec>`")

Copy link
Member Author

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".
@amotl amotl merged commit d0dfab2 into master Jan 29, 2024
21 checks passed
@amotl amotl deleted the amo/add-timeout branch January 29, 2024 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants