Skip to content

Conversation

@elprans
Copy link
Member

@elprans elprans commented Mar 30, 2017

The timeout logic is currently a bit of a mess. This commit attempts to
tidy things up.

Most importantly, the timeout budget is now applied consistently to the
entire call, whereas previously multiple consecutive operations used
the same timeout value, making it possible for the overall run time to
exceed the timeout.

Secondly, tighten the validation for timeouts: booleans are not
accepted, and neither any value that cannot be converted to float.

@elprans elprans requested a review from 1st1 March 30, 2017 22:24
@elprans elprans self-assigned this Mar 30, 2017
'invalid command_timeout value: '
'expected non-negative float (got {!r})'.format(
command_timeout))

Copy link
Member

Choose a reason for hiding this comment

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

Rewrite this block to:

try: if isinstance(command_timeout, bool): raise ValueError command_timeout = float(command_timeout) if command_timeout < 0: raise ValueError except ValueError: raise ValueError( 'invalid command_timeout value: ' 'expected non-negative float (got {!r})'.format( command_timeout)) from None
except ValueError:
raise ValueError(
'invalid timeout value: expected non-negative float '
'(got {!r})'.format(timeout)) from None
Copy link
Member

Choose a reason for hiding this comment

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

if timeout is not None: try: if type(timeout) is bool: raise ValueError timeout = float(timeout) except ValueError: raise ValueError( 'invalid timeout value: expected non-negative float ' '(got {!r})'.format(timeout)) from None

return result

async def _do_execute_with_timeout(self, query, executor, timeout,
Copy link
Member

Choose a reason for hiding this comment

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

Even though I suggested to split _do_execute in two methods myself, I now think we'd be better off to merge them in one :) The actual timeouts arithmetic happens just in two places, so we can just add two if statements to _do_execute.

The timeout logic is currently a bit of a mess. This commit attempts to tidy things up. Most importantly, the timeout budget is now applied consistently to the _entire_ call, whereas previously multiple consecutive operations used the same timeout value, making it possible for the overall run time to exceed the timeout. Secondly, tighten the validation for timeouts: booleans are not accepted, and neither any value that cannot be converted to float.
@1st1 1st1 merged commit 1674dec into master Mar 30, 2017
@elprans elprans deleted the timeouts branch April 4, 2017 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants