-
-
Notifications
You must be signed in to change notification settings - Fork 952
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
Contextvars are not reset between requests if the request contains multipart form data #2335
Comments
I can't reproduce on the latest versions of the packages, and considering Python 3.9 and 3.10. If you can create a repository, and show me in the CI how this fails, I can continue helping. |
I can reproduce your MRE using |
I'm having the same issue with Python 3.11.9 and In my case, I'm doing simple JSON POST, but I only notice it on "high enough" loads. |
I can confirm this bug. |
Uvicorn uses |
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: