Skip to content
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

🐛 Close FormData (uploaded files) after the request is done #5465

Merged
merged 8 commits into from Nov 3, 2022
4 changes: 4 additions & 0 deletions fastapi/routing.py
Expand Up @@ -3,6 +3,7 @@
import email.message
import inspect
import json
from contextlib import AsyncExitStack
from enum import Enum, IntEnum
from typing import (
Any,
Expand Down Expand Up @@ -190,6 +191,9 @@ async def app(request: Request) -> Response:
if body_field:
if is_body_form:
body = await request.form()
stack = request.scope.get("fastapi_astack")
assert isinstance(stack, AsyncExitStack)
stack.push_async_callback(body.close)
else:
body_bytes = await request.body()
if body_bytes:
Expand Down