-
Notifications
You must be signed in to change notification settings - Fork 475
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
Remove catch-all exception logger for asyncio tasks #605
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,25 +6,12 @@ | |
tasks_registry = [] | ||
|
||
|
||
def log_if_exception(reraise_cancelled: bool, future: asyncio.Future) -> None: | ||
try: | ||
if exc := future.exception(): | ||
logger.exception( | ||
f"Vocode wrapped logger; exception raised by task {future}: {exc}", | ||
exc_info=exc, | ||
) | ||
except asyncio.CancelledError: | ||
if reraise_cancelled: | ||
raise | ||
|
||
|
||
def asyncio_create_task_with_done_error_log( | ||
def asyncio_create_task( | ||
*args, | ||
reraise_cancelled: bool = False, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this would be a regression to remove this, right? remind me again what happens to tasks normally when they get cancelled There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not removing it though? It's just a method rename to not have "with done error log" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you referring to the reraise_cancelled part? That part didn't make sense to me because we only check for an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I'm referring to the reraise_cancelled part There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reading back the code, this is safe - all |
||
**kwargs, | ||
) -> asyncio.Task: | ||
task = asyncio.create_task(*args, **kwargs) | ||
tasks_registry.append(task) | ||
task.add_done_callback(functools.partial(log_if_exception, reraise_cancelled)) | ||
task.add_done_callback(lambda t: tasks_registry.remove(t)) | ||
return task |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is fine - i understand why we need
tasks_registry
, but I wonder if we audit the use-cases and eventually remove this methodThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The primary reason I removed this is because each exception log causes a duplicate error in sentry. And we can just catch them by the raised error. Is there a scenario where we actually need this method/functionality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe we keep tasks in
tasks_registry
so that these tasks don't get garbage collected when they aren't assigned to some state in a worker, e.g.i was thinking we would eventually remove it and replace it with
asyncio.create_task
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sure, you're talking about the method in general, not the change I made. Yeah eventually should be good to change to
asyncio.create_task