-
-
Notifications
You must be signed in to change notification settings - Fork 342
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
fix: event handler error breaks stream #2810
Conversation
Before this PR, the request that triggers the error event returns OK, then we get a weird asgi message, and on next request that emits an event we get a 500 error:
After this PR the exception is caught and logged, and the next event emitting request succeeds:
|
a9d4b2f
to
46c1f40
Compare
46c1f40
to
8e77858
Compare
This PR prevents exceptions raised from within event handlers from closing the event receive stream, and from further propagation beyond the event emitter backend. When an exception is caught from an event handler, we log it at ERROR level. Closes #2809
8e77858
to
d0dbdc5
Compare
Kudos, SonarCloud Quality Gate passed! |
Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/2810 |
await self._run_listener_in_task_group(*item) | ||
|
||
@staticmethod | ||
async def _run_listener_in_task_group(fn: Any, args: tuple[Any], kwargs: dict[str, Any]) -> None: |
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 solution is a bit of an issue unfortunately, as creating a new task group for every received item will prevent them running concurrently. I think the proper fix here would be to wrap the listeners in an exception handler and then run those in the task group
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.
@peterschutt I can cook up a PR for this later unless you want to fix it :)
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.
OK, I'll leave it to you - thanks.
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.
Actually, I got it - my mess, I'll clean it up.
Pull Request Checklist
Description
This PR prevents exceptions raised from within event handlers from closing the event receive stream, and from further propagation beyond the event emitter backend.
When an exception is caught from an event handler, we log it at ERROR level.
Close Issue(s)
Closes #2809