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

Potential error in task handling code #588

Closed
cderici opened this issue Nov 19, 2021 · 0 comments · Fixed by #589
Closed

Potential error in task handling code #588

cderici opened this issue Nov 19, 2021 · 0 comments · Fixed by #589
Labels
kind/bug indicates a bug in the project

Comments

@cderici
Copy link
Contributor

cderici commented Nov 19, 2021

If the utils.run_with_interrupt is ever called with log=None,

async def run_with_interrupt(task, *events, log=None):
"""
Awaits a task while allowing it to be interrupted by one or more
`asyncio.Event`s.
If the task finishes without the events becoming set, the results of the
task will be returned. If the event become set, the task will be cancelled
``None`` will be returned.
:param task: Task to run
:param events: One or more `asyncio.Event`s which, if set, will interrupt
`task` and cause it to be cancelled.
"""
task = jasyncio.create_task_with_handler(task, 'tmp', log)
event_tasks = [jasyncio.ensure_future(event.wait()) for event in events]
done, pending = await jasyncio.wait([task] + event_tasks,

then it'll cause the jasyncio.create_task_with_handler

def create_task_with_handler(coro, task_name, logger):

to break at the following line if the wrapped task raises an exception:

logger.exception("Task %s raised an exception: %s" % (task_name, e))


PR to follow with a small fix.

@cderici cderici added the kind/bug indicates a bug in the project label Nov 19, 2021
cderici added a commit to cderici/python-libjuju that referenced this issue Nov 19, 2021
jujubot added a commit that referenced this issue Nov 19, 2021
#589

#### Description

This fixes a potential intermittent bug in task handling.

Fixes #588

#### QA Steps

```sh
N/A
```

#### Notes & Discussion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug indicates a bug in the project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant