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

Cleanup the system resources of webhook servers/tunnels #874

Merged
merged 1 commit into from
Dec 3, 2021

Conversation

nolar
Copy link
Owner

@nolar nolar commented Dec 1, 2021

The webhook server/tunnel protocol is extended with an optional part: it can now be an asynchronous context manager. This is a more explicit way of cleaning up the system resources than relying on the finally: block or the GeneratorExit exception. The latter is not guaranteed to happen until the generator is garbage-collected, which can happen much later than expected (or never). In that case, the resources remain leaked and can fail the tests. For example, this was happening in PyPy 3.8.

The webhook servers & tunnels provided by Kopf support both protocols: the simple callable protocol (with the cleanup on garbage collection in the finally: block) and the async context manager (with the explicit cleanup on exiting).

Related: #872.

@nolar nolar added the enhancement New feature or request label Dec 1, 2021
@lgtm-com
Copy link

lgtm-com bot commented Dec 1, 2021

This pull request introduces 2 alerts when merging 15cd0e0 into a9aa4ed - view on LGTM.com

new alerts:

  • 1 for Unused import
  • 1 for Module is imported with 'import' and 'import from'

The webhook server/tunnel protocol is extended with an optional part: it can now be an asynchronous context manager. This is a more explicit way of cleaning up the system resources than relying on the `finally:` block or the `GeneratorExit` exception. The latter is not guaranteed to happen until the generator is garbage-collected, which can happen much later than expected (or never). In that case, the resources remain leaked and can fail the tests. For example, this was happening in PyPy 3.8.

The webhook servers & tunnels provided by Kopf support both protocols: the simple callable protocol (with the cleanup on garbage collection in the `finally:` block) and the async context manager (with the explicit cleanup on exiting).

Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
@nolar nolar merged commit 7d4e7f8 into main Dec 3, 2021
@nolar nolar deleted the webhook-resources-cleanup branch December 3, 2021 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant