You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by simon-sk October 26, 2023
Hi Starlette team,
we are experiencing an issue with Starlette where contextvars set in a middleware are leaking between requests if the request contains multi-part form data and the client session is reused.
I constructed a minimal example which sets a context var in a middleware and resets it after the app has been called. It also raises an exception if the var is already set:
This results in a server error due to the fact that the variable is already set (sometimes it is necessary to run the client script multiple times as the issue does not always occur).
If I execute the same script without multipart data, it works without issues:
...
r=client.post(url, timeout=None)
...
We have also experienced this issue without sending multipart form data for requests within the same client session but it occurs significantly less often and unfortunately I am not able to reproduce it consistently.
We experienced this issue with Python 3.9 and 3.10, Starlette v0.31.1, and uvicorn v0.23.2.
The text was updated successfully, but these errors were encountered:
@Kludex I created a repo here that reproduces the issue in this action run.
The issue does not always occur on the first request, so I added a loop that sends multiple requests in a row.
I can reproduce your MRE using uvicorn running with the AsyncIO event loop on Python 3.9. I cannot reproduce with the latest Python version, and I also can't reproduce with uvloop.
Discussed in #2312
Originally posted by simon-sk October 26, 2023
Hi Starlette team,
we are experiencing an issue with Starlette where
contextvars
set in a middleware are leaking between requests if the request contains multi-part form data and the client session is reused.I constructed a minimal example which sets a context var in a middleware and resets it after the app has been called. It also raises an exception if the var is already set:
Then, I execute a second script which calls this endpoint using a
httpx
client and includes a files object:This results in a server error due to the fact that the variable is already set (sometimes it is necessary to run the client script multiple times as the issue does not always occur).
If I execute the same script without multipart data, it works without issues:
We have also experienced this issue without sending multipart form data for requests within the same client session but it occurs significantly less often and unfortunately I am not able to reproduce it consistently.
We experienced this issue with Python 3.9 and 3.10, Starlette v0.31.1, and uvicorn v0.23.2.
The text was updated successfully, but these errors were encountered: