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

wait for timeout before cancelling scheduled tasks #157

Closed
wants to merge 2 commits into from
Closed

wait for timeout before cancelling scheduled tasks #157

wants to merge 2 commits into from

Conversation

n8sty
Copy link

@n8sty n8sty commented Feb 11, 2020

Resolves #72

What do these changes do?

Resolves issue raised by @Dock1100 in #72. Brief description of the issue is that handlers were not being gracefully shutdown.

Are there changes in behavior for the user?

This should make aiojobs operate in a manner that I believe is consistent with what is promised by its documentation.

Related issue number

#72

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> (e.g. 588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the PR
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: Fix issue with non-ascii contents in doctest text files.

@aio-libs aio-libs deleted a comment from CLAassistant Nov 21, 2020
@Dreamsorcerer
Copy link
Member

I don't think this change is correct. A task should be cancelled immediately, as the code currently does. After cancellation, a task must then be awaited to give it a chance to handle the cancellation. The timeout is there in case the task is misbehaving and not cancelling quickly.

Your change results in cancelling without awaiting afterwards, which means the task may not get to handle any cleanup from the cancellation. You'll likely also end up with unawaited warnings.

I think to fix the original bug, would either need some explicit logic for @atomic, or maybe a new Scheduler.wait_and_close() method or similar, which actually waits on the existing jobs with a timeout before initiating a close.

Personally, I'd be more interested in fixing this from the aiohttp side and having aiohttp give handlers a moment to finish processing before shutting everything down.

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.

Aiohttp: graceful shutdown doesn't wait for aiojob.asyncio.atomic handler to finish within canceled request.
2 participants