I'm converting a Flask app to Quart and trying not to change too much, so for now I'm making requests on the server using the requests
library, and just wrapping them in run_sync
.
So I converted:
response: Response = session.request(
method,
url,
params=params,
data=data,
headers=headers,
json=json,
files=files,
cookies=cookies,
timeout=(connect_timeout, timeout),
)
to
response: Response = await run_sync(lambda: session.request(
method,
url,
params=params,
data=data,
headers=headers,
json=json,
files=files,
cookies=cookies,
timeout=(connect_timeout, timeout),
))()
This all works fine except I've experienced a small but significant uptick in errors that I'm unable to reproduce locally. I can't tell right now if the errors come from some kind of timeout or some other edge case when working with requests
+ async + Quart's run_sync
. If I use Quart, but just revert the session.request(...)
to a synchronous call, the uptick in errors goes away.
I'm using gunicorn with UvicornWorker
to run the app, using uvloop
for the async framework.
It may line up with a CancelledError
that I see in logs, but I'm not sure, and not sure why the session.request
coroutine would be getting cancelled.
What might be causing this?