-
-
Notifications
You must be signed in to change notification settings - Fork 943
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
Reraise exception from background task #2696
base: master
Are you sure you want to change the base?
Conversation
return { | ||
"type": "http.request", | ||
"body": self._body, | ||
"more_body": False, | ||
} | ||
return {"type": "http.request", "body": self._body, "more_body": False} |
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.
Ignore this. It was just getting me crazy.
return { | ||
"type": "http.request", | ||
"body": b"", | ||
"more_body": False, | ||
} | ||
return {"type": "http.request", "body": b"", "more_body": False} |
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.
Ignore this. It was just getting me crazy.
return { | ||
"type": "http.request", | ||
"body": chunk, | ||
"more_body": not self._stream_consumed, | ||
} | ||
return {"type": "http.request", "body": chunk, "more_body": not self._stream_consumed} |
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.
Ignore this. It was just getting me crazy.
# import traceback | ||
# traceback.print_exc() |
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.
If you uncomment those lines, you can see that we have the exceptions on the app_exc
, but we don't reraise them at any point.
@@ -175,6 +165,8 @@ async def body_stream() -> typing.AsyncGenerator[bytes, None]: | |||
if not message.get("more_body", False): | |||
break | |||
|
|||
await anyio.sleep(0) |
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.
It looks like this is enough to make the switch so we have time to run the coro
task after the break
above.
This shouldn't be the way to solve this issue... Also, it breaks one of the tests.
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.
doesn't this only work because in the test case in the PR description, the background task that fails isn't really async so a single task switch (via sleep(0)
) is enough to trigger the exception, but a background task that does await would still not be triggered by this?
Assuming await self.app
finishes all background tasks, the coro
that awaits the app here could signal an event that can be awaited here instead.
@jhominal Any idea here? |
Currently, the exceptions on the background tasks are swallowed: