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

Repeat API calls on timeouts #358

Merged
merged 10 commits into from
May 19, 2021
Merged

Repeat API calls on timeouts #358

merged 10 commits into from
May 19, 2021

Conversation

azawlocki
Copy link
Contributor

@azawlocki azawlocki commented Apr 29, 2021

Changes in this PR:

  • Make the Executor retry some operations that raise errors that indicate timeouts in API calls:
    • Invoice.accept()
    • DebitNote.accept()
  • Ignore timeout errors in operations that are executed periodically:
    • collect_offers()
    • get_invoice_events()
    • get_debit_note_events()

The "timeout errors" are HTTP errors 408 and 504, asyncio.TimeoutError (indicating client-side timeout) and intermittent errors aiohttp.ClientDisconnectedError and aiohttp.ClientOSError(errno=32) (Broken Pipe).

Should fix:

Note: "should fix" is obviously an overstatement, this PR won't prevent timeout-related API errors, it merely repeats each failed API call few times, making an assumption that the more attempts we make the less likely is that they will all fail.

@azawlocki azawlocki requested a review from a team April 29, 2021 13:37
@azawlocki azawlocki changed the base branch from master to b0.5 April 29, 2021 13:38
@azawlocki azawlocki requested a review from filipgolem April 29, 2021 13:39
@azawlocki azawlocki changed the title Repeat calls to Invoice.accept() and DebitNode.accept() on timeouts Repeat calls to payment API calls on timeouts Apr 29, 2021
@azawlocki azawlocki changed the title Repeat calls to payment API calls on timeouts Repeat API calls on timeouts Apr 30, 2021
try:
proposals = await self._api.collect_offers(self._id, timeout=10, max_events=10)
async with SuppressedExceptions(is_recoverable_exception):
proposals = await self._api.collect_offers(self._id, timeout=5, max_events=10)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wrapping this call in SuppressedExceptions(is_recoverable_exception) would ignore timeout errors and aiohttp.ServerDisconnectedError.

@azawlocki azawlocki requested a review from shadeofblue May 5, 2021 08:12
@maaktweluit
Copy link
Contributor

Awesome fixes! 🥳

FYI the core team needs to double check if the re-tries are handled properly before releasing..
when is this planned for release? ( tomorrow's patch or next patch? )

Copy link
Contributor

@filipgolem filipgolem left a comment

Choose a reason for hiding this comment

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

I like this PR very much. I would change the default interval to e.g. 0.5s (it's 0.0s currently) and max_tries to 3.

@azawlocki azawlocki force-pushed the az/repeat-invoice-accept branch from 9825e90 to fdca644 Compare May 6, 2021 17:39
@azawlocki azawlocki requested a review from mbenke May 6, 2021 17:42
Copy link
Contributor

@shadeofblue shadeofblue left a comment

Choose a reason for hiding this comment

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

all-ok-here-22822524

Comment on lines +73 to 74
@repeat_on_error(max_tries=5)
async def details(self) -> AllocationDetails:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that this method is never called, so there is no need to add @repeat_on_error here.

@nieznanysprawiciel
Copy link
Contributor

I tested these changes with yagna daemon. Internal timeouts values were random, so that sometimes calls fail and sometimes succeed.
Yapapi is retrying accept_invoice properly and yagna daemon is able to handle it even after timeout.

@azawlocki azawlocki merged commit c62fcce into b0.5 May 19, 2021
@azawlocki azawlocki deleted the az/repeat-invoice-accept branch May 19, 2021 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants